void setThirdColumnDropDownListButton_Click(object sender, EventArgs e)
{
// Create a header drop down list without default down down items.
HeaderDropDownList headerDropDownList = new HeaderDropDownList();
DropDownItemCollection dropDownItemCollection = headerDropDownList.Items;
// Initialize drop down items manually.
// Add show all item.
dropDownItemCollection.Add(new DropDownShowAllFilterItem());
DropDownAutoFilterItem autoFilterItem = new DropDownAutoFilterItem();
autoFilterItem.DropDownItemNeeded += new EventHandler<DropDownItemNeededEventArgs>(autoFilterItem_DropDownItemNeeded);
// custom range item.
dropDownItemCollection.Add(autoFilterItem);
// Get second column header cell.
ColumnHeaderCell columnHeaderCell = this.gcMultiRow1.ColumnHeaders[0][2] as ColumnHeaderCell;
columnHeaderCell.DropDownList = headerDropDownList;
}
void autoFilterItem_DropDownItemNeeded(object sender, DropDownItemNeededEventArgs e)
{
int filterValue = int.Parse(e.FilterValue.ToString());
e.DropDownCustomFilterItem = new AutoRangeFilterItem(filterValue / 100);
e.Handled = true;
}
public class AutoRangeFilterItem : DropDownCustomFilterItem
{
public AutoRangeFilterItem(int filterValue)
: base(filterValue)
{
}
public override string Text
{
get
{
return ((int)FilterValue * 100).ToString() + " to " + (((int)FilterValue + 1) * 100).ToString();
}
set { }
}
protected override bool Check(object value)
{
// check the value whether in specific range.
int checkedValue = int.Parse(value.ToString());
return (checkedValue >= ((int)FilterValue * 100) && checkedValue <= (((int)FilterValue + 1) * 100));
}
}
Private Sub setThirdColumnDropDownListButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles setThirdColumnDropDownListButton.Click
' Create a header drop down list without default down down items.
Dim headerDropDownList As New HeaderDropDownList()
Dim dropDownItemCollection As DropDownItemCollection = headerDropDownList.Items
' Initialize drop down items manually.
' Add show all item.
dropDownItemCollection.Add(New DropDownShowAllFilterItem())
Dim autoFilterItem As New DropDownAutoFilterItem()
AddHandler autoFilterItem.DropDownItemNeeded, AddressOf autoFilterItem_DropDownItemNeeded
' custom range item.
dropDownItemCollection.Add(autoFilterItem)
' Get second column header cell.
Dim columnHeaderCell As ColumnHeaderCell = TryCast(Me.gcMultiRow1.ColumnHeaders(0)(2), ColumnHeaderCell)
columnHeaderCell.DropDownList = headerDropDownList
End Sub
Private Sub autoFilterItem_DropDownItemNeeded(ByVal sender As Object, ByVal e As DropDownItemNeededEventArgs)
Dim filterValue As Integer = Integer.Parse(e.FilterValue.ToString())
e.DropDownCustomFilterItem = New AutoRangeFilterItem(filterValue / 100)
e.Handled = True
End Sub
Public Class AutoRangeFilterItem
Inherits DropDownCustomFilterItem
Public Sub New(ByVal filterValue As Integer)
MyBase.New(filterValue)
End Sub
Public Overloads Overrides Property Text() As String
Get
Return (DirectCast(FilterValue, Integer) * 100).ToString() + " to " + ((DirectCast(FilterValue, Integer) + 1) * 100).ToString()
End Get
Set(ByVal value As String)
End Set
End Property
Protected Overloads Overrides Function Check(ByVal value As Object) As Boolean
' check the value whether in specific range.
Dim checkedValue As Integer = Integer.Parse(value.ToString())
Return (checkedValue >= (DirectCast(FilterValue, Integer) * 100) AndAlso checkedValue <= ((DirectCast(FilterValue, Integer) + 1) * 100))
End Function
End Class