| MultiRow Windows Forms > Developer's Guide > Using MultiRow > Headers > Filtering Rows using the Column Headers |
You can use the column header cell and commands in the drop-down list to filter rows.

![]() |
|
You need to set the HeaderDropDownList class instance into the ColumnHeaderCell.DropDownList property to set a drop-down list. Additionally, to enable the filter commands, you need to set the second argument of the constructor to True.
This example creates a filter.
Imports GrapeCity.Win.MultiRow
Dim template As Template = template.Default
Dim columnHeaderCell As ColumnHeaderCell = _
DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
columnHeaderCell.DropDownList = _
New HeaderDropDownList("textBoxCell1", True, False)
template.Row.Cells("textBoxCell1").Style.BackColor = Color.Azure
GcMultiRow1.Template = template
|
using GrapeCity.Win.MultiRow;
Template template = Template.Default;
ColumnHeaderCell columnHeaderCell = template.ColumnHeaders[0].Cells[0] as ColumnHeaderCell;
columnHeaderCell.DropDownList =
new HeaderDropDownList("textBoxCell1", true, false);
template.Row.Cells["textBoxCell1"].Style.BackColor = Color.Azure;
gcMultiRow1.Template = template;
|
You can specify the range of rows to be filtered using the HeaderDropDownList.StartRow and HeaderDropDownList.EndRow properties.
The first 1000 different values in the row filter range are counted by default. You can check this value using the DropDownAutoFilterItem.MaxCount property. The DropDownAutoFilterItem class creates the list of filter candidates automatically, depending on the different values. You can improve the performance while displaying the drop-down, by reducing the number of values counted for filtering.
The code shown below counts the first 100 different values.
Imports GrapeCity.Win.MultiRow
Dim template As Template = template.Default
Dim columnHeaderCell As ColumnHeaderCell = _
DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
Dim headerDropDownList As HeaderDropDownList = _
New HeaderDropDownList("textBoxCell1", True, False)
For Each item As DropDownItem In headerDropDownList.Items
If TypeOf item Is DropDownAutoFilterItem Then
Dim dropDownAutoFilterItem As DropDownAutoFilterItem = _
DirectCast(item, DropDownAutoFilterItem)
dropDownAutoFilterItem.MaxCount = 100
End If
Next
columnHeaderCell.DropDownList = headerDropDownList
template.Row.Cells("textBoxCell1").Style.BackColor = Color.Azure
GcMultiRow1.Template = template
' Set the sample data
GcMultiRow1.AllowUserToAddRows = False
GcMultiRow1.RowCount = 200
For i As Integer = 0 To GcMultiRow1.RowCount - 1
GcMultiRow1(i, "textBoxCell1").Value = i.ToString()
Next
|
using GrapeCity.Win.MultiRow;
Template template = Template.Default;
ColumnHeaderCell columnHeaderCell = template.ColumnHeaders[0].Cells[0] as ColumnHeaderCell;
HeaderDropDownList headerDropDownList = new HeaderDropDownList("textBoxCell1", true, false);
foreach (DropDownItem item in headerDropDownList.Items)
{
if (item is DropDownAutoFilterItem)
{
DropDownAutoFilterItem dropDownAutoFilterItem = item as DropDownAutoFilterItem;
dropDownAutoFilterItem.MaxCount = 100;
}
}
columnHeaderCell.DropDownList = headerDropDownList;
template.Row.Cells["textBoxCell1"].Style.BackColor = Color.Azure;
gcMultiRow1.Template = template;
// Set the sample data
gcMultiRow1.AllowUserToAddRows = false;
gcMultiRow1.RowCount = 200;
for (int i = 0; i < gcMultiRow1.RowCount; i++)
{
gcMultiRow1[i, "textBoxCell1"].Value = i.ToString();
}
|
You can use the GcMultiRow.ClearAllFilters method to collectively clear all the filters that are set.
The following code uses the ClearAllFilters method.
GcMultiRow1.ClearAllFilters() |
gcMultiRow1.ClearAllFilters(); |
You can use the ColumnHeaderCell.DropDownButtonImages property to set an indicator image in the drop button of the filter. Set the ColumnHeaderCell.ShowDropDownButtonImages property to True to enable the ColumnHeaderCell.DropDownButtonImages property settings.
![]() |
The filter indicator does not support zoom. |
The following code sets the image of an indicator which is displayed when the filter is executed.
Imports GrapeCity.Win.MultiRow
Dim template As Template = template.Default
Dim columnHeaderCell As ColumnHeaderCell = DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
Dim headerDropDownList1 As New HeaderDropDownList()
headerDropDownList1.Items.Add(New DropDownAutoFilterItem())
columnHeaderCell.FilterCellName = "textBoxCell1"
columnHeaderCell.DropDownList = headerDropDownList1
columnHeaderCell.DropDownButtonImages.Filtered = New Bitmap("test.bmp")
columnHeaderCell.ShowDropDownButtonImages = True
GcMultiRow1.Template = template
|
using GrapeCity.Win.MultiRow; Template template = Template.Default; ColumnHeaderCell columnHeaderCell = template.ColumnHeaders[0].Cells[0] as ColumnHeaderCell; HeaderDropDownList headerDropDownList1 = new HeaderDropDownList(); headerDropDownList1.Items.Add(new DropDownAutoFilterItem()); columnHeaderCell.FilterCellName = "textBoxCell1"; columnHeaderCell.DropDownList = headerDropDownList1; columnHeaderCell.DropDownButtonImages.Filtered = new Bitmap(@"test.bmp"); columnHeaderCell.ShowDropDownButtonImages = true; gcMultiRow1.Template = template; |
You can exclude frozen rows from filtering by setting the GcMultiRow.ExcludeFreezeRowsWhenFilter property to True.
![]() |
If the GcMultiRow.ExcludeFreezeRowsWhenFilter property is set to True, the values of the frozen rows are not displayed in the filter's drop-down list. |
The following code excludes 10 rows from the bottom of the grid, from filtering.
GcMultiRow1.FreezeBottomRowCount = 10 GcMultiRow1.ExcludeFreezeRowsWhenFilter = True |
gcMultiRow1.FreezeBottomRowCount = 10; gcMultiRow1.ExcludeFreezeRowsWhenFilter = true; |
You can use the ColumnHeaderCell.DropDownContextMenuStrip property to set multiple selection filters. Set the HeaderDropDownContextMenu.Items property to an instance of the AutoFilterToolStripItem class, and set it to the ColumnHeaderCell.DropDownContextMenuStrip property to use the multiple selection filters.
![]() |
|
This example creates multiple selection filters.
Imports GrapeCity.Win.MultiRow
Dim textBoxCell1 As New TextBoxCell()
textBoxCell1.Name = "textBoxCell1"
Dim template As Template = template.CreateGridTemplate(New Cell() {textBoxCell1})
Dim columnHeaderCell = DirectCast(template.ColumnHeaders(0).Cells(0), ColumnHeaderCell)
columnHeaderCell.DropDownList = New HeaderDropDownList("textBoxCell1", False, False)
Dim headerDropDownContextMenu1 As New HeaderDropDownContextMenu()
headerDropDownContextMenu1.Items.Add(New AutoFilterToolStripItem())
columnHeaderCell.DropDownContextMenuStrip = headerDropDownContextMenu1
GcMultiRow1.Template = template
|
using GrapeCity.Win.MultiRow;
TextBoxCell textBoxCell1 = new TextBoxCell();
textBoxCell1.Name = "textBoxCell1";
Template template = Template.CreateGridTemplate(new Cell[] { textBoxCell1 });
ColumnHeaderCell columnHeaderCell = template.ColumnHeaders[0].Cells[0] as ColumnHeaderCell;
columnHeaderCell.DropDownList = new HeaderDropDownList("textBoxCell1", false, false);
template.Row.Cells["textBoxCell1"].Style.BackColor = Color.Azure;
HeaderDropDownContextMenu headerDropDownContextMenu1 = new HeaderDropDownContextMenu();
headerDropDownContextMenu1.Items.Add(new AutoFilterToolStripItem());
columnHeaderCell.DropDownContextMenuStrip = headerDropDownContextMenu1;
gcMultiRow1.Template = template;
|
Use the following steps to set multiple selection filters in the designer.