我只是将数据库绑定到Datasource,并定义了display和valuemember。但是现在我需要让用户可以对项目的项目进行排序(上/下)是否可能?
答案 0 :(得分:1)
ListBox遵循DataSource中的行顺序。因此,您必须在DataSource中操作行。
首先,我通常在DataSource DataSet和GUI对象之间放置一个DataTable:
Dim dtMyTable1 as New Datatable
' Load your data from database into dtMyTable
dtMyTable1 = ds.tables(0) ' data from your dabase...
' do any re-ordering or data manipulation here... I.e.:
Dim dr1 as DataRow = dtMyTable1.rows(5)
Dim dr2 as DataRow = dtMyTable1.rows(6)
dtMyTable1.Rows.RemoveAt(5)
dtMyTable1.Rows.InsertAt(dr2,5)
dtMyTable1.Rows.RemoveAt(6)
dtMyTable1.Rows.InsertAt(dr1,6)
' assign Datatable to ListBox
Me.ListBox1.datasource = dtMyTable1