Listview单击标题列 [英] Listview click header column
本文介绍了Listview单击标题列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想按时间或付款或名称在列表视图中订购商品。我现在正在使用组合框;但我想从列表视图标题中执行它,当我单击标题列时,我希望列表视图按其排序。
我使用此代码与组合框请帮助我。
请参阅图片 [ ^ ]。
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[^].
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
推荐答案
如果你看一下 ListView.ColumnClick事件 [ ^ ]他们提供的示例是按列排序...
If you have a look at the MSDN documentation for the ListView.ColumnClick event[^] the example they give is sorting by a column...
这篇关于Listview单击标题列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文