[Serializable()]
//Create a subclass inheriting BaseFilterItem class.
public class CustomFilter : FarPoint.Win.Spread.BaseFilterItem
{
FarPoint.Win.Spread.SheetView sv = null;
public CustomFilter()
{
}
public CustomFilter(FarPoint.Win.Spread.SheetView sheetView)
{
this.sv = sheetView;
}
//---------------------------------------------------------
//Return names to be displayed in the drop-down list.
//---------------------------------------------------------
public override string DisplayName
{
get { return "Extract any values that are greater than 10 and less than 50."; }
}
//-----------------------------------------------------------------------------------------
//Set sheets to filters.
//-----------------------------------------------------------------------------------------
public override FarPoint.Win.Spread.SheetView SheetView
{
set { sv = value; }
}
//-----------------------------------------------------------------------------------------
//Evaluate specified values by conditions.
//-----------------------------------------------------------------------------------------
public bool IsFilteredIn(int value)
{
if (!(value == null) & (value >= 10) & (value <= 50))
{
//Return True only when the following conditions are satisfied.
//(1)Values are entered.
//(2)Values are not lower than 10.
//(3)Values are not greater than 50.
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)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
int[] returnList = null;
int row = 0;
if ((sv == null))
{
return returnList;
}
for (row = 0; row <= sv.RowCount - 1; row++)
{
if (!(sv.GetValue(row, columnIndex) == null))
{
int value = (int)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;
}
}
private void Form1_Load(object sender, EventArgs e)
{
//Display only custom filters created in Column1.
FarPoint.Win.Spread.FilterColumnDefinition fcd = new FarPoint.Win.Spread.FilterColumnDefinition(0, FarPoint.Win.Spread.FilterListBehavior.Custom);
FarPoint.Win.Spread.HideRowFilter hf = new FarPoint.Win.Spread.HideRowFilter(fpSpread1.ActiveSheet);
hf.AddColumn(fcd);
fpSpread1.ActiveSheet.RowFilter = hf;
//Add the custom filter created for Column1.
CustomFilter cfi = new CustomFilter(fpSpread1.ActiveSheet);
FarPoint.Win.Spread.FilterColumnDefinition ccd = fpSpread1.ActiveSheet.RowFilter.GetFilterColumnDefinition(0);
ccd.Filters.Add(cfi);
fpSpread1.ActiveSheet.DefaultStyle.CellType = new FarPoint.Win.Spread.CellType.NumberCellType();
fpSpread1.ActiveSheet.SetValue(0, 0, 10);
fpSpread1.ActiveSheet.SetValue(1, 0, 100);
fpSpread1.ActiveSheet.SetValue(2, 0, 50);
fpSpread1.ActiveSheet.SetValue(3, 0, 40);
fpSpread1.ActiveSheet.SetValue(4, 0, 80);
fpSpread1.ActiveSheet.SetValue(5, 0, 1);
fpSpread1.ActiveSheet.SetValue(6, 0, 65);
fpSpread1.ActiveSheet.SetValue(7, 0, 20);
fpSpread1.ActiveSheet.SetValue(8, 0, 30);
fpSpread1.ActiveSheet.SetValue(9, 0, 35);
}