Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2005

Tip: Looking for answers? Try searching our database.

ComboBox autofiltering items - using RowFilter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andreiwid - 17 Oct 2005 13:35 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.