MESCIUS SPREAD for Windows Forms 15.0J
AutoFilterIndex プロパティ (ColumnHeader)
使用例 

複数の列ヘッダ行があるときに、行フィルタインジケータを表示する列ヘッダ行を取得または設定します。
構文
'宣言
 
Public Property AutoFilterIndex As Integer
public int AutoFilterIndex {get; set;}

プロパティ値

行のインデックスを表す Integer
解説

ヘッダに複数の列ヘッダ行がある場合は、このプロパティを設定することで、フィルタ インジケータを表示する行を指定できます。インデックスを指定するには、このプロパティを0から n-1 までのいずれかの値に設定します(0は一番上の行、n はヘッダの行数を示します)。n-1 よりも大きい値にすると、フィルタ インジケータは単に一番下の行に表示されます。

このプロパティの設定で、フィルタ インジケータを表示する行をたとえばヘッダ行3と指定し、その後列ヘッダ行の数を3未満に変更した場合、フィルタ インジケータは RowCount プロパティを -1に設定した場合と同様、一番下の行に表示されます。ただし、その後ヘッダ行の数を3以上に変更すると、フィルタ インジケータは再びヘッダ行3に表示されます。コントロールに表示される列ヘッダの行数は、RowCount プロパティで指定します。

このプロパティが効力を持つのは、Visible プロパティ(または SheetView.ColumnHeaderVisible プロパティ)が True に設定されていて、なおかつ列ヘッダ行が非表示でない場合です。

使用例
次のサンプルコードは、フィルタアイコンを表示する列ヘッダ内の行を指定します。
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
参照

ColumnHeader クラス
ColumnHeader メンバ

 

 


© MESCIUS inc. All rights reserved.