We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I speed up search in GridDataBoundGrid control?

 

The GridDataBoundGrid search can be speed up by finding the string through the grid data set records instead loop through the grid cells. The ArrayList maintains the filtered records which has the matching search string. Using the arraylist, you can find the record index of the matched string.

C#

private GridRangeInfo[] FindAllFast(string search, int column)

{

ArrayList searchArray = new ArrayList();

CurrencyManager cm = (CurrencyManager)this.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember];

int field = this.gridDataBoundGrid1.Binder.ColIndexToField(column);

for (int i = 0; i < cm.Count; ++i)

{

DataRowView drv = (DataRowView)cm.List[i];

String str = drv.Row[field].ToString();

searchArray.Add(str.ToUpper());

}

ArrayList foundCells = new ArrayList();

try

{

this.Cursor = Cursors.WaitCursor;

int index = searchArray.IndexOf(search.ToUpper());

while (index > -1)

{

foundCells.Add(GridRangeInfo.Cell(index + 1, column));

index = searchArray.IndexOf(search.ToUpper(), index + 1);

}

}

catch { }

finally

{

this.Cursor = Cursors.Default;

}

return (GridRangeInfo[])foundCells.ToArray(typeof(GridRangeInfo));

}

VB

Private Function FindAllFast(ByVal search As String, ByVal column As Integer) As GridRangeInfo()

Dim searchArray As ArrayList = New ArrayList()

Dim cm As CurrencyManager = CType(Me.BindingContext(Me.gridDataBoundGrid1.DataSource, Me.gridDataBoundGrid1.DataMember), CurrencyManager)

Dim field As Integer = Me.gridDataBoundGrid1.Binder.ColIndexToField(column)

For i As Integer = 0 To cm.Count - 1

Dim drv As DataRowView = CType(cm.List(i), DataRowView)

Dim str As String = drv.Row(field).ToString()

searchArray.Add(str.ToUpper())

Next i

Dim foundCells As ArrayList = New ArrayList()

Try

Me.Cursor = Cursors.WaitCursor

Dim index As Integer = searchArray.IndexOf(search.ToUpper())

Do While index > -1

foundCells.Add(GridRangeInfo.Cell(index + 1, column))

index = searchArray.IndexOf(search.ToUpper(), index + 1)

Loop

Catch

Finally

Me.Cursor = Cursors.Default

End Try

Return CType(foundCells.ToArray(GetType(GridRangeInfo)), GridRangeInfo())

End Function

Please refer the sample in the below link which illustrates the above: http://websamples.syncfusion.com//samples/KB/Grid.Windows/Grid_Search/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
766 04/30/2011 07/10/2014 WinForms GridDataBoundGrid(Classic)
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon