GrapeCity MultiRow Windows Forms Documentation
Filtering Rows using the Column Headers

You can use the column header cell and commands in the drop-down list to filter rows.

Column Header Dropdown

  • Filter cannot be used in virtual mode.
  • New rows are not considered while filtering.

Setting the Drop-down list

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.

Using Code

This example creates a filter.

[VB]

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

[CS]

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;

Specifying the Filter Range

You can specify the range of rows to be filtered using the HeaderDropDownList.StartRow and HeaderDropDownList.EndRow properties.

Counting the Values

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.

Using Code

The code shown below counts the first 100 different values.

[VB]

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

[CS]

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();
}

Clearing the Filter

You can use the GcMultiRow.ClearAllFilters method to collectively clear all the filters that are set.

Using Code

The following code uses the ClearAllFilters method.

[VB]

GcMultiRow1.ClearAllFilters()

[CS]

 
gcMultiRow1.ClearAllFilters();

Filter Indicator

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.

Using Code

The following code sets the image of an indicator which is displayed when the filter is executed.

[VB]

 
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

[CS]

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;

Excluding Frozen Rows from Filtering

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.

Using Code

The following code excludes 10 rows from the bottom of the grid, from filtering.

[VB]

GcMultiRow1.FreezeBottomRowCount = 10
GcMultiRow1.ExcludeFreezeRowsWhenFilter = True

[CS]

 
gcMultiRow1.FreezeBottomRowCount = 10;
gcMultiRow1.ExcludeFreezeRowsWhenFilter = true;

Multiple Selection Filters

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.

  • If the DropDownContextMenuStrip property is not empty, the filter settings of the ColumnHeaderCell.DropDownList property become invalid.
  • The DropDownContextMenuStrip property does not support the display of the designer in the Runtime tab.

Using Code

This example creates multiple selection filters.

[VB]

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

[CS]

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.

  1. Select the cell on which you wish to set the multiple selection filter (for example: columnHeaderCell1).
  2. Select the DropDownList property from the Properties window, and select FilterDropDownList.
  3. Select the DropDownList.CellName property from the Properties window, and select the cell on which you want to perform filtering (for example: textBoxCell1).
  4. Select the DropDownContextMenuStrip property from the Properties window, and select Add New to add a HeaderDropDownContextMenu on the template (for example: headerDropDownContextMenu1).
  5. Select the HeaderDropDownContextMenu, then select the Items property and click the ... button.
  6. Check that showAllToolStripItem1 is set in the Members list of the Item Collection Editor that is displayed.
  7. Click the OK button and close the window.
  8. Run the project.
  9. Display the drop-down list of columnHeaderCell1, and confirm that the multiple selection filter is displayed.
See Also

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options