Hi guys!
I need a help from you.
I would like to do an autofiltering ComboBox. There is a ComboBox as
DropDown style and its items come from a DataView. Well, when user types on
that control (Text property) it should filter the rows inside using the
DataView.RowFilter property and, in the same time, shows to user its items
(DroppedDown = True) already filtered. I've tried the following:
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
Dim strRowFilter As String
strRowFilter = String.Concat("Name LIKE '%", ComboBox1.Text, "%'")
DataView1.RowFilter = strRowFilter
ComboBox1.DroppedDown = True
End Sub
As you can see, when the users types on ComboBox's Text property the event
KeyUp is raised. Then, its Text content becames a Filter string, eg. "John"
goes "Name LIKE '%John%'" and that string to RowFilter.
My solution for this issue isn't working. When I type the Text I can se the
items but for just the first letter.
Thanks in advance.
Henrry Pires - 17 Oct 2005 14:54 GMT
Hi
Try this code:
'somewhere alter fill you dataview
ComboBox1.SelectedItem = Nothing
Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
'save the original text
Dim str As String = ComboBox1.Text
'make the filter
dv.RowFilter = "Name LIKE '%" & ComboBox1.Text & "%'"
'celar the select value
ComboBox1.SelectedItem = Nothing
'set the original text
ComboBox1.Text = str
'put the focus at the end of the string
ComboBox1.SelectionStart = str.Length
'open the combo box
ComboBox1.DroppedDown = True
End Sub
> Hi guys!
>
[quoted text clipped - 24 lines]
>
> Thanks in advance.
Andreiwid - 17 Oct 2005 15:31 GMT
Thanks a lot Henrry!
the code refined:
Private Sub ComboBox2_KeyUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles ComboBox2.KeyUp
If e.KeyCode >= Keys.A And e.KeyCode <= Keys.Z Or e.KeyCode =
Keys.Back Or e.KeyCode = Keys.Delete Then
Dim strTemp As String = ComboBox2.Text
If strTemp.Trim.CompareTo(String.Empty) = 0 Then
dtvCBOCliFor.RowFilter = String.Empty
Else
Dim strRowFilter As String = String.Concat("NomeRazSocial
LIKE '%", ComboBox2.Text, "%'")
dtvCBOCliFor.RowFilter = strRowFilter
End If
ComboBox2.Text = strTemp
ComboBox2.SelectionStart = strTemp.Length
ComboBox2.DroppedDown = True
End If
End Sub
> Hi
> Try this code:
[quoted text clipped - 59 lines]
> >
> > Thanks in advance.