sergeiweerasuriya
asked on
clearing a combo box
I have 2 combo boxes and below is the code.
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml" )
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd ex)
If Not cboPostcode.Items.Contains (ds.Tables (0).Rows(r owIndex)(" Post_Code" )) Then
cboPostcode.Items.Add(ds.T ables(0).R ows(rowInd ex)("Post_ Code"))
End If
Next
End Sub
Private Sub cboPostcode_SelectedIndexC hanged(ByV al sender As Object, ByVal e As System.EventArgs) Handles cboPostcode.SelectedIndexC hanged
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml" )
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd ex)
If row("Post_Code") = cboPostcode.Text Then
If Not cboStreet.Items.Contains(d s.Tables(0 ).Rows(row Index)("Ad d_Line2")) Then
cboStreet.Items.Add(ds.Tab les(0).Row s(rowIndex )("Add_Lin e2"))
End If
End If
Next
End Sub
Private Sub cboStreet_SelectedIndexCha nged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboStreet.SelectedIndexCha nged
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml" )
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd ex)
If row("Post_Code") = cboPostcode.Text And row("Add_Line2") = cboStreet.Text Then
lstStreetAddresses.Items.A dd(ds.Tabl es(0).Rows (rowIndex) ("Add_Line 1"))
End If
Next
End Sub
Lets say the at first i select cboPostcode, then click and select on the cboStreet and get the value to the list box. Now if i select another value from the cboPostcode the cboStreet should clear itself and then add the relevant record. All the items from the list should also be cleared. How do i do that?
Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml"
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd
If Not cboPostcode.Items.Contains
cboPostcode.Items.Add(ds.T
End If
Next
End Sub
Private Sub cboPostcode_SelectedIndexC
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml"
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd
If row("Post_Code") = cboPostcode.Text Then
If Not cboStreet.Items.Contains(d
cboStreet.Items.Add(ds.Tab
End If
End If
Next
End Sub
Private Sub cboStreet_SelectedIndexCha
Dim ds As DataSet = New DataSet
Dim Customers As DataTable
Dim rowIndex As Integer
Dim row As DataRow
ds.ReadXml("Customers.xml"
Customers = ds.Tables.Item(0)
For rowIndex = 0 To Customers.Rows.Count - 1
row = Customers.Rows.Item(rowInd
If row("Post_Code") = cboPostcode.Text And row("Add_Line2") = cboStreet.Text Then
lstStreetAddresses.Items.A
End If
Next
End Sub
Lets say the at first i select cboPostcode, then click and select on the cboStreet and get the value to the list box. Now if i select another value from the cboPostcode the cboStreet should clear itself and then add the relevant record. All the items from the list should also be cleared. How do i do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.