Click here to Skip to main content
15,867,838 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to order the items in a list view by the time or payment or name. I am now usingw the combo box; but I would like to do it from the list view header when I clicked on the header column I would like the list view sorted by it.
I am use this code with the combo box please help me.

See the picture[^].
VB
Private Sub OrderBy()
Try
    Dim OB As String
    If ComboBox1.Text = "ID" Then
        OB = "ID"
    ElseIf ComboBox1.Text = "Name" Then
        OB = "StudentName"
    ElseIf ComboBox1.Text = "Payment" Then
        OB = "Payment"
    ElseIf ComboBox1.Text = "Time" Then
        OB = "LessonTime"
    ElseIf ComboBox1.Text = "Date" Then
        OB = "LessonDate"
    End If

    Dim dt As New DataTable
    Dim ds As New DataSet
    ds.Tables.Add(dt)
    Dim da As New OleDbDataAdapter("select * from Tend order by " & OB & "", con)
    da.Fill(dt)
    Dim myrow As DataRow
    For Each myrow In dt.Rows
        ListView1.Items.Add(myrow.Item(0))
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(1))
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(2))
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(3))
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(4))
        ListView1.Items(ListView1.Items.Count - 1).SubItems.Add(myrow.Item(5))
    Next
Posted
Updated 9-Feb-14 0:15am
v3

1 solution

If you have a look at the MSDN documentation for the ListView.ColumnClick event[^] the example they give is sorting by a column...
 
Share this answer
 

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