Spread Windows Forms 11.0 Product Documentation
AutoFilterIndex Property (ColumnHeader)
Example 


FarPoint.Win.Spread Assembly > FarPoint.Win.Spread Namespace > ColumnHeader Class : AutoFilterIndex Property
Gets or sets which column header row displays the row filter indicator when there are multiple column header rows.
Syntax
'Declaration
 
Public Property AutoFilterIndex As Integer
'Usage
 
Dim instance As ColumnHeader
Dim value As Integer
 
instance.AutoFilterIndex = value
 
value = instance.AutoFilterIndex
public int AutoFilterIndex {get; set;}

Property Value

Integer index of the row
Remarks

If your header has multiple column header rows, you can specify which row displays the filtering indicator by setting this property. To specify the index, set the property to a value between 0 and n-1, where 0 is the top row and n is the number of header rows. Any value above n-1 simply puts the filtering indicator in the bottom row.

If you set this property to specify a row to display the filtering indicator, for example, header row 3, and then later change the number of column header rows to be less than 3, the filtering indicator is displayed in the bottom row, as if the RowCount property is set to -1. However, if you then change the number of header rows to 3 or greater, the filtering indicator is again displayed in header row 3. Use the RowCount property to specify how many column header rows the component displays.

This property does not have an effect unless the Visible property (or the SheetView.ColumnHeaderVisible property) is set to true and the column header rows are not hidden.

Example
This example designates the row in the column headers in which to display the filter icon.
fpSpread1.ActiveSheet.ColumnHeaderRowCount = 3;
fpSpread1.ActiveSheet.ColumnHeader.AutoFilterIndex = 1;

FarPoint.Win.Spread.NamedStyle instyle = new FarPoint.Win.Spread.NamedStyle();
FarPoint.Win.Spread.NamedStyle outstyle = new FarPoint.Win.Spread.NamedStyle();
instyle.BackColor = Color.Yellow;
outstyle.BackColor = Color.Aquamarine;

FarPoint.Win.Spread.FilterColumnDefinition fcd = new FarPoint.Win.Spread.FilterColumnDefinition(1);
FarPoint.Win.Spread.FilterColumnDefinition fcd1 = new FarPoint.Win.Spread.FilterColumnDefinition(2);
FarPoint.Win.Spread.FilterColumnDefinition fcd2 = new FarPoint.Win.Spread.FilterColumnDefinition(3);

CustomFilter cfi = new CustomFilter(fpSpread1.ActiveSheet);
fcd.Filters.Add(cfi);

FarPoint.Win.Spread.StyleRowFilter srf = new FarPoint.Win.Spread.StyleRowFilter(fpSpread1.ActiveSheet, instyle, outstyle);
srf.AddColumn(fcd);
srf.AddColumn(fcd1);
srf.AddColumn(fcd2);

fpSpread1.ActiveSheet.RowFilter = srf;

[Serializable()]
public class CustomFilter : FarPoint.Win.Spread.BaseFilterItem //Create a sub-class inheriting BaseFilterItem class.
{
   FarPoint.Win.Spread.SheetView sv = null;

   public CustomFilter() : base()
   {
   }

   public CustomFilter(FarPoint.Win.Spread.SheetView sheetView): base()
   {
      this.sv = sheetView;
   }

   //Returns names to be displayed in a drop-down list.
   public override string DisplayName
   {
      get
      {
         return "Contains an 'A'";
      }
   }

   //Set sheets to filters.
   public override FarPoint.Win.Spread.SheetView SheetView
   {
      set
      {
         sv = value;
      }
   }

   //Evaluate specified values by particular conditions.
   public bool IsFilteredIn(object value)
   {
      if (!((object)value == null) && value is string && ((string)value).Contains('A'))
      {
         return true;
      }
      return false;
   }

   //Display names returned by DisplayName property.
   public override bool ShowInDropDown(int columnIndex, int[] filteredInRowList)
   {
      return true;
   }

   //Execute filtering in the column specified in a sheet.
   public override int[] Filter(int columnIndex)
   {
      ArrayList list = new ArrayList();
      int[] returnList = null;
      int row;

      if (sv == null)
      {
         return returnList;
      }

      for (row = 0; row <= (sv.RowCount - 1); row++)
      {
         if ((object)sv.GetValue(row, columnIndex) != null)
         {
            object value = (object)sv.GetValue(row, columnIndex);
            if (IsFilteredIn(value))
            {
               //Add row indexes that meet conditions sequentially.
               list.Add(row);
            }
         }
      }

      //When there are any rows that meet conditions, copy them to arrays.
      if (list.Count > 0)
      {
         returnList = new int[list.Count];
         list.CopyTo(returnList);
         list.Clear();
      }

      //Return all row indexes that meet conditions.
      return returnList;
   }

   //When any data that has to be serialized is included in a custom filter class, override it.
   public override bool Serialize(System.Xml.XmlTextWriter w)
   {
      w.WriteStartElement("CustomFilter");
      base.Serialize(w);
      w.WriteEndElement();
      return true;
   }

   public override bool Deserialize(System.Xml.XmlNodeReader r)
   {
      if (r.NodeType == System.Xml.XmlNodeType.Element)
      {
         if (r.Name.Equals("CustomFilter"))
         {
            base.Deserialize(r);
         }
      }
      return true;
   }
}
fpSpread1.ActiveSheet.ColumnHeaderRowCount = 3
fpSpread1.ActiveSheet.ColumnHeader.AutoFilterIndex = 1
    
Dim instyle As New FarPoint.Win.Spread.NamedStyle()
Dim outstyle As New FarPoint.Win.Spread.NamedStyle()
instyle.BackColor = Color.Yellow
outstyle.BackColor = Color.Aquamarine
    
Dim fcd As New FarPoint.Win.Spread.FilterColumnDefinition(1)
Dim fcd1 As New FarPoint.Win.Spread.FilterColumnDefinition(2)
Dim fcd2 As New FarPoint.Win.Spread.FilterColumnDefinition(3)
    
Dim cfi As New CustomFilter(fpSpread1.ActiveSheet)
fcd.Filters.Add(cfi)
    
Dim srf As New FarPoint.Win.Spread.StyleRowFilter(fpSpread1.ActiveSheet, instyle, outstyle)
srf.AddColumn(fcd)
srf.AddColumn(fcd1)
srf.AddColumn(fcd2)
    
fpSpread1.ActiveSheet.RowFilter = srf

<Serializable()>
'Create a sub-class inheriting BaseFilterItem class.
Public Class CustomFilter Inherits FarPoint.Win.Spread.BaseFilterItem
   Private sv As FarPoint.Win.Spread.SheetView = Nothing

   Public Sub New() : MyBase
   End Sub

   Public Sub New(ByVal sheetView As FarPoint.Win.Spread.SheetView) : MyBase
      Me.sv = sheetView
   End Sub

   'Returns names to be displayed in a drop-down list.
   Public Overrides ReadOnly Property DisplayName() As String
      Get
         Return "Contains an 'A'"
      End Get
   End Property

   'Set sheets to filters.
   Public Overrides WriteOnly Property SheetView() As FarPoint.Win.Spread.SheetView
      Set(ByVal value As FarPoint.Win.Spread.SheetView)
         sv = value
      End Set
   End Property

   'Evaluate specified values by particular conditions.
   Public Function IsFilteredIn(ByVal value As Object) As Boolean
      If Not (CObj(value) Is Nothing) AndAlso TypeOf value Is String AndAlso (CStr(value)).Contains("A") Then
         Return True
      End If
         Return False
   End Function

   'Display names returned by DisplayName property.
   Public Overrides Function ShowInDropDown(ByVal columnIndex As Integer, ByVal filteredInRowList As Integer()) As Boolean
      Return True
   End Function

   'Execute filtering in the column specified in a sheet.
   Public Overrides Function Filter(ByVal columnIndex As Integer) As Integer()
      Dim list As ArrayList = New ArrayList()
      Dim returnList As Integer() = Nothing
      Dim row As Integer

      If sv Is Nothing Then
         Return returnList
      End If

      For row = 0 To (sv.RowCount - 1) Step row+1
         If CObj(sv.GetValue(row, columnIndex)) IsNot Nothing Then
            Dim value As Object = CObj(sv.GetValue(row, columnIndex))
            If IsFilteredIn(value) Then
               list.Add(row)
            End If
         End If
      Next

      'When there are any rows that meet conditions, copy them to arrays.
      If list.Count > 0 Then
         returnList = New Integer(list.Count) {}
         list.CopyTo(returnList)
         list.Clear()
      End If

      'Return all row indexes that meet conditions.
      Return returnList
   End Function

   'When any data that has to be serialized is included in a custom filter class, override it.
   Public Overrides Function Serialize(ByVal w As System.Xml.XmlTextWriter) As Boolean
      w.WriteStartElement("CustomFilter")
      MyBase.Serialize(w)
      w.WriteEndElement()
      Return True
   End Function

   Public Overrides Function Deserialize(ByVal r As System.Xml.XmlNodeReader) As Boolean
      If r.NodeType = System.Xml.XmlNodeType.Element Then
         If r.Name.Equals("CustomFilter") Then
            MyBase.Deserialize(r)
         End If
      End If
      Return True
   End Function
End Class
See Also

Reference

ColumnHeader Class
ColumnHeader Members