This project is read-only.

A Filter by Search Terms Function VERY SLOW!

Dec 17, 2009 at 4:41 AM
Edited Dec 17, 2009 at 4:43 AM
I have written this function, and works very well, but when i have many items (i have tried with 8000 aprox) is very slow!
how can i do the same thing but faster???
Note: Im not using databinding, im creating the cells on the fly with a datareader without any editor, only text

'Private Shared matchesView As SourceGrid.Cells.Views.Cell

'Private Shared Function GetMatchesView() As SourceGrid.Cells.Views.Cell
' If matchesView Is Nothing Then : matchesView = New SourceGrid.Cells.Views.Cell
' matchesView.Border = New DevAge.Drawing.RectangleBorder( _
' New DevAge.Drawing.BorderLine(Color.Gold, 2, Drawing2D.DashStyle.Dash, 0))
' matchesView.BackColor = Color.Yellow
' End If
' Return matchesView
'End Function

Public Shared Sub FilterBySearch(ByRef grid As SourceGrid.Grid, ByRef searchText As String)
	Dim searchTerms() As String = searchText.ToLower.Split(New Char() {Char.Parse(";")}, System.StringSplitOptions.RemoveEmptyEntries)
	Dim inCells As Integer
	Dim inRows As Integer
	grid.SuspendLayout() '1. Tried this
	grid.Hide() '2. Tried this
	'And tried Both
	'Shows all Rows
    For row As Integer = 1 To grid.RowsCount - 1 'Dont take care with row 0 (is header)
		If Not grid.Rows(row).Visible Then grid.Rows(row).Visible = True 'Tried with if (in case that property performs some code when sets a value)
	Dim temp As String
	If searchTerms.Length > 0 Then 'Hides Rows that no match any search term
		For row As Integer = 1 To grid.RowsCount - 1 'Dont take care with row 0 (is header)
			inRows = 0
			For column As Integer = 0 To grid.ColumnsCount - 1
				inCells = 0
				If grid.Item(row, column).Value IsNot Nothing Then
					Debug.Print(String.Format("row {0}, column {1}", row, column))
					temp = grid.Item(row, column).Value.ToString.ToLower
					For Each term In searchTerms
						If temp.Contains(term) Then 'I founded a match
							inCells += 1 
							Exit For
						End If
				End If
				If inCells > 0 Then
					inRows += 1 
					'grid.Item(row, column).View = GetMatchesView()
				End If
			If inRows = 0 Then : grid.Rows(row).Visible = False : End If
	End If
    grid.ResumeLayout() '1. Tried this
	grid.Show() '2. Tried this
End Sub

Dec 17, 2009 at 5:55 AM

Could you have a look at what is going on when you call this method with dotTrace?

You should be able to download evaluation license, which should be enough for one month.

After you profile, search for the function which might be cause for the problem. if you find that, please describe what is going on. Maybe then we will be able to think of something together

Dec 17, 2009 at 9:33 AM

Far now i have modified the function to set all rows.visible to false and then show the matched rows.visible to true, is a little more fast...

I have debugged step by step, the problem remains in slowness when changing the .Visible property of the row ( is more slow when setting true, than setting false)
and also is slow the cell value.toString retrieval in the loop.

Give me some time i will do a testing using dotTrace, i not have slept tonight and i have to finish the step 1 of a proyect for presentation in the next days.

Do you have implemented in some way a kind of Filter like this some time? or you always use Filterings updating a datasource using databinding?
Im starting to think that is my initial problem for all problems that im having now.

(Sorry for my english is better when i'm awake ) ;)

Thanks in advance!