一般在datagridview 直接支援排序,但是 dataset 卻沒跟著排序;即可採用此方法來做
------------
Private Sub DGridV_ColumnHeaderMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGridV.ColumnHeaderMouseClick
Try
If e.RowIndex <= -1 Then
Dim ColumnName As String = DGridV.Columns(e.ColumnIndex).Tag
Dim dv As DataView = odst.Tables(0).DefaultView
Dim sort As String = ""
Select Case DGridV.SortOrder
Case 1
dv.Sort = ColumnName & " ASC"
sort = ColumnName & " ASC"
Case 2
dv.Sort = ColumnName & " DESC"
sort = ColumnName & " DESC"
End Select
'--
odst.Tables.Clear()
odst.Tables.Add(dv.ToTable)
'-
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
沒有留言:
張貼留言