Sorting a DataSet and passing values to a Combo box

I have an XML file of the following structure as given below: I have passed the xml data to a DataSet. I have two combo boxes on the form. The first combo box should list down all the post codes available(the same postcode should not repeat). Once you select the postcode the other combo box should list down all the "Add_Line2" values(the same value should not repeat). Then when i select the "Add_Line2" value from the combo box all the "Add_Line1" values should appear on a list box. I don't know how to do it. The only way i know how to do this by codingit in a way that all the post codes will be repeated in the postcodes combo box and so on....PLEASE HELP.

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Customers>
    <Cus_fname>allan</Cus_fname>
    <Cus_lname>ellison</Cus_lname>
    <Tel>0792438456</Tel>
    <Add_Line1>2</Add_Line1>
    <Add_Line2>shrewsbury road</Add_Line2>
    <Post_Code>st174dl</Post_Code>
    <Day_Read>175</Day_Read>
    <Night_Read>245</Night_Read>
  </Customers>
  <Customers>
    <Cus_fname>peter</Cus_fname>
    <Cus_lname>king</Cus_lname>
    <Tel>01785443224</Tel>
    <Add_Line1>34</Add_Line1>
    <Add_Line2>cramer street</Add_Line2>
    <Post_Code>st165dg</Post_Code>
    <Day_Read>150</Day_Read>
    <Night_Read>400</Night_Read>
  </Customers>
</NewDataSet>
sergeiweerasuriyaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nayernaguibCommented:
You can use the following code:

_______________________________________________

        For i = 0 To ds.Tables(0).Rows.Count
            If Not comboPostcodes.Items.Contains(ds.Tables(0).Rows(i)("Post_Code")) Then
                comboPostcodes.Items.Add(ds.Tables(0).Rows(i)("Post_Code"))
            End If
            If Not comboLine2.Items.Contains(ds.Tables(0).Rows(i)("Add_Line2")) Then
                comboLine2.Items.Add(ds.Tables(0).Rows(i)("Add_Line2"))
            End If
            If Not listLine1.Items.Contains(ds.Tables(0).Rows(i)("Add_Line1")) Then
                listLine1.Items.Add(ds.Tables(0).Rows(i)("Add_Line1"))
            End If
        Next

_______________________________________________

_______________

  Nayer Naguib
sergeiweerasuriyaAuthor Commented:
where do i write this? In Form Load?
sergeiweerasuriyaAuthor Commented:
I need to say "if the selected item in the combo box is x then do this" . What is the line of code for it?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

toocrazy007Commented:
If ComboLine1.SelectedText="x" Then
'Statements that you want to fire when the condition is true
End if
nayernaguibCommented:
You can use the SelectedIndexChanged event handler of the combobox to execute code when the user makes a selection from a combobox.
To refer to the text of the selected item, use the SelectedText property of the combobox.

_______________

  Nayer Naguib
sergeiweerasuriyaAuthor Commented:
This is the code i have written below. Only the first combo box gets populated. why?

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(rowIndex)
            If Not cboPostcode.Items.Contains(ds.Tables(0).Rows(rowIndex)("Post_Code")) Then
                cboPostcode.Items.Add(ds.Tables(0).Rows(rowIndex)("Post_Code"))
            End If
        Next
    End Sub

    Private Sub cboPostcode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboPostcode.SelectedIndexChanged
        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(rowIndex)
            If row("Post_Code") = cboPostcode.SelectedText Then
                If Not cboStreet.Items.Contains(ds.Tables(0).Rows(rowIndex)("Add_Line2")) Then
                    cboStreet.Items.Add(ds.Tables(0).Rows(rowIndex)("Add_Line2"))
                End If
            End If
        Next

    End Sub

    Private Sub cboStreet_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboStreet.SelectedIndexChanged
        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(rowIndex)
            If row("Post_Code") = cboPostcode.SelectedText And row("Add_Line2") = cboStreet.SelectedText Then
                lstStreetAddresses.Items.Add(ds.Tables(0).Rows(rowIndex)("Add_Line2"))
            End If
        Next
    End Sub
sergeiweerasuriyaAuthor Commented:
The combo box postcode should be populated at the form load. The combo box street should be populated only when you make a selection from the postcode combo box. The list box should be populated only when a selection been made in combo box street.
nayernaguibCommented:
Use the ComboBox.Text property rather than ComboBox.SelectedText.

_______________

  Nayer Naguib

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sergeiweerasuriyaAuthor Commented:
The code is finally working . thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.