Articles in this section
Category / Section

How to make filter bar use textboxes and have display respond to each keystroke?

1 min read

 

To get Textbox filtering, you can derive the GridFilterBar class and handle the CurrentCellChanged event handler. Below is the code snippet:

C#

public class GridTextBoxFilterBar : GridFilterBar

{

private GridDataBoundGrid _grid;

private DataTable _dataTable;

private DataSet ds;

public override void WireGrid(Syncfusion.Windows.Forms.Grid.GridDataBoundGrid grid,

Syncfusion.Windows.Forms.Grid.GridStyleInfo style)

{

if(_grid != null)

UnwireGrid();

if(grid != null)

{

_dataTable = grid.DataSource as DataTable;

if(_dataTable == null)

{

ds = grid.DataSource as DataSet;

if(ds != null)

{

_dataTable = ds.Tables[grid.DataMember];

}

}

if(_dataTable != null)

{

//add a fixed row at the top

grid.Model.Data.RowCount++;

grid.Model.Rows.HeaderCount++;

int _row = grid.Model.Rows.HeaderCount;

grid.Model.Rows.FrozenCount = grid.Model.Rows.FrozenCount + 1;

grid.Model.ChangeCells(GridRangeInfo.Cells(_row, 1, _row, grid.Model.ColCount), style, StyleModifyType.Override);

GridBorder border = grid.BaseStylesMap["Standard"].StyleInfo.Borders.Right;

for(int col = 1; col <= grid.Model.ColCount; ++col)

{

grid[_row, col].Borders.Right = border;

}

grid.CurrentCellChanged += new EventHandler(grid_FilterCellChanged);

}

}

_grid = grid;

}

}

VB

Public Class GridTextBoxFilterBar : Inherits GridFilterBar

Private _grid As GridDataBoundGrid

Private _dataTable As DataTable

Private ds As DataSet

Public overloads Overrides Sub WireGrid(ByVal grid As Syncfusion.Windows.Forms.Grid.GridDataBoundGrid, ByVal style As

Syncfusion.Windows.Forms.Grid.GridStyleInfo)

If Not _grid Is Nothing Then

UnwireGrid()

End If

If Not grid Is Nothing Then

_dataTable = CType(IIf(TypeOf grid.DataSource Is DataTable, grid.DataSource, Nothing), DataTable)

If _dataTable Is Nothing Then

ds = CType(IIf(TypeOf grid.DataSource Is DataSet, grid.DataSource, Nothing), DataSet)

If Not ds Is Nothing Then

_dataTable = ds.Tables(grid.DataMember)

End If

End If

If Not _dataTable Is Nothing Then

'add a fixed row at the top

grid.Model.Data.RowCount += 1

grid.Model.Rows.HeaderCount += 1

Dim _row As Integer = grid.Model.Rows.HeaderCount

grid.Model.Rows.FrozenCount = grid.Model.Rows.FrozenCount + 1

grid.Model.ChangeCells(GridRangeInfo.Cells(_row, 1, _row, grid.Model.ColCount), style, StyleModifyType.Override)

Dim border As GridBorder = grid.BaseStylesMap("Standard").StyleInfo.Borders.Right

Dim col As Integer = 1

Do While col <= grid.Model.ColCount

grid(_row, col).Borders.Right = border

col += 1

Loop

AddHandler grid.CurrentCellChanged, AddressOf grid_FilterCellChanged

End If

End If

_grid = grid

End Sub

End Class

Sample:


http://websamples.syncfusion.com/samples/kb/grid.windows/GDBGTextBoxFilter/main.htm


Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied