Click here to Skip to main content
15,884,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I have many Comboboxes in my form (win forms). i was setting the dropdownstyle as DropDown for Autocomplete. If we are entering the data into first combobox then related data coming into the second combobox and so on. If we are clear the data of first combobox(Autocomplete), second comboboxes also cleared. But problem is doesn't cleared the second Combobox and also remaining comboboxes.


I wrote single method for all comboboxes(Autocomplete )

VB
Public Sub AutoCompleteDropDown(ByVal str As String, ByVal AutoDropDown As ComboBox, ByVal strText As String)
       Try
           AutoDropDown.AutoCompleteCustomSource = Nothing
           Dim dt As DataTable = GetTable(str)

           If dt.Rows.Count > 0 Then

               For Each prow As DataRow In dt.Rows

                   AutoDropDown.Items.Add(prow(0))
               Next
           Else
               MessageBox.Show("No " & AutoDropDown.Name.Remove(0, 3) & " exists", strText, MessageBoxButtons.OK, MessageBoxIcon.Information)
               Exit Sub
           End If
           AutoDropDown.AutoCompleteMode = AutoCompleteMode.Suggest
           AutoDropDown.AutoCompleteSource = AutoCompleteSource.ListItems

           DropDownCollection.Clear()

           For Each drjob As DataRow In dt.Rows

               DropDownCollection.Add(drjob(0).ToString())
           Next

           AutoDropDown.AutoCompleteCustomSource = DropDownCollection

       Catch ex As Exception
           MessageBox.Show(ex.Message, strText, MessageBoxButtons.OK, MessageBoxIcon.Information)
       End Try

   End Sub


first calling in load page for 1st combobox and load the data to 2nd combobox in 1st combobox
Posted
Updated 14-Mar-13 10:40am
v6
Comments
Karthik Harve 12-Mar-13 6:09am    
could show your code, where you are clearing the comboboxes on change of first combobox ?
CH Guravaiah 12-Mar-13 6:17am    
in 1st combobox , i was cleared the remaining comboboxes .
Example : combobox2.items.clear(); and combobox2.text=string.empty
agnesn88 13-Mar-13 2:40am    
you can download some free sample codes here--->http://codeslibrary.net/sc.php?id=3188&code=Autocomplete%20for%20winform%20combo%20box

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900