Hi,
I have a textbox that is filled using autocomplete. The autocomplete is a globally accessible sub that I use for textboxes and (I guess) comboboxes.
My problem is that the autocomplete sub takes several seconds to fill the textbox. Is there some way my code could be improved? (The code below takes three seconds to fill for 288 autocomplete entries, which I don't think should be a lot for this kind of functionality.)
My best bet is that the autosorcecollection has to redraw itself every time an entry is added, and that causes the delay, but I'm not sure.
Apart from taking time I think this global function is really handy, so feel free to use!
Thanks a lot for suggestions,
/Pettrer
dt = PoulateDT("SELECT cCode, cText, ID FROM MyTable WHERE inUse=1 ORDER BY cCode")
FillAutocomplete(txtSearchBox, dt, "cCode")
Public Sub FillAutocomplete(ByVal MyControl As Object, ByVal dt As DataTable, ByVal ColName As String)
Dim str As String = Now().ToString
MyControl.AutoCompleteMode = AutoCompleteMode.SuggestAppend
MyControl.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim autoSourceCollection As New AutoCompleteStringCollection()
MyControl.AutoCompleteCustomSource = autoSourceCollection
Dim drow As DataRow
For Each drow In dt.Rows
autoSourceCollection.Add(drow.Item(ColName))
Next
str &= " " & Now.ToString
End Sub
I have a textbox that is filled using autocomplete. The autocomplete is a globally accessible sub that I use for textboxes and (I guess) comboboxes.
My problem is that the autocomplete sub takes several seconds to fill the textbox. Is there some way my code could be improved? (The code below takes three seconds to fill for 288 autocomplete entries, which I don't think should be a lot for this kind of functionality.)
My best bet is that the autosorcecollection has to redraw itself every time an entry is added, and that causes the delay, but I'm not sure.
Apart from taking time I think this global function is really handy, so feel free to use!
Thanks a lot for suggestions,
/Pettrer
dt = PoulateDT("SELECT cCode, cText, ID FROM MyTable WHERE inUse=1 ORDER BY cCode")
FillAutocomplete(txtSearchBox, dt, "cCode")
Public Sub FillAutocomplete(ByVal MyControl As Object, ByVal dt As DataTable, ByVal ColName As String)
Dim str As String = Now().ToString
MyControl.AutoCompleteMode = AutoCompleteMode.SuggestAppend
MyControl.AutoCompleteSource = AutoCompleteSource.CustomSource
Dim autoSourceCollection As New AutoCompleteStringCollection()
MyControl.AutoCompleteCustomSource = autoSourceCollection
Dim drow As DataRow
For Each drow In dt.Rows
autoSourceCollection.Add(drow.Item(ColName))
Next
str &= " " & Now.ToString
End Sub