How to pass sorted Data from a DataSet to a DataGrid

Below is the structure of an XML file i have. I have populated a DataSet with the Data from the XML file. What i want to do is sort the data from the DataSet and display the sorted data in a DataGrid. How do i do this?

<?xml version="1.0" standalone="yes"?>
<NewDataSet>
  <Customers>
    <Cus_fname>aaaaaaaa</Cus_fname>
    <Cus_lname>aaaaaaaaa</Cus_lname>
    <Tel>aaaaaaaa</Tel>
    <Add_Line1>aaaaaaaaa</Add_Line1>
    <Add_Line2>aaaaaaaa</Add_Line2>
    <Post_Code>aaaaaaa</Post_Code>
    <Day_Read>aaaaaaaa</Day_Read>
    <Night_Read>aaaaaa</Night_Read>
  </Customers>
  <Customers>
    <Cus_fname>bbb</Cus_fname>
    <Cus_lname>bbb</Cus_lname>
    <Tel>bbb</Tel>
    <Add_Line1 />
    <Add_Line2 />
    <Post_Code />
    <Day_Read>bbb</Day_Read>
    <Night_Read>bbb</Night_Read>
  </Customers>
</NewDataSet>


Below is the code i have written so far.

        Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click

        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("Cus_fname") = txtCustomerFirstName.Text  Then
               
                              'populate the dataGrid

            End If

        Next
    End Sub

What is the code for populating the sorted data to the DataGrid?
sergeiweerasuriyaAsked:
Who is Participating?
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:
Here's how you can sort your data:

        ds.Tables(0).DefaultView.Sort = "columnName" 'the name of the field to use for sorting

and the following line will populate the DataGrid:

        MyDataGrid.DataSource = ds.Tables(0)

_______________

  Nayer Naguib
0
sergeiweerasuriyaAuthor Commented:
what if i used two columns for sorting.
0
sergeiweerasuriyaAuthor Commented:
Here's what i want to do. I want to put that particular row into the dataGrid. The following code puts all the rows in the DataSet to the Grid.

ds.ReadXml("Customers.xml")

        Customers = ds.Tables.Item(0)
        For rowIndex = 0 To Customers.Rows.Count - 1
            row = Customers.Rows.Item(rowIndex)
            If row("Cus_fname") = txtCustomerFirstName.Text Then
                txtCustomerFirstName.Text = row("Cus_fname")
                txtCustomerLastName.Text = row("Cus_lname")
                txtAddressLine1.Text = row("Add_Line1")
                txtAddressLine2.Text = row("Add_Line2")
                txtPostcode.Text = row("Post_Code")
                txtDayRead.Text = row("Day_Read")
                txtNightRead.Text = row("Night_Read")

                ds.Tables(0).DefaultView.Sort = "Cus_fname"
                DataGrid1.DataSource = ds.Tables(0)
            End If
0
nayernaguibCommented:
Use the expression:

        ds.Tables(0).DefaultView.Sort = "column1,column2,..."

_______________

  Nayer Naguib
0
nayernaguibCommented:
Add the row(s) that you want to show in the DataGrid to a newly created table (foe example, ds.Tables(1)).
Next, set the data source of the DataGrid to this table.

_______________

  Nayer Naguib
0

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
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.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.