如何确定DataGridView
是否已排序?我需要获得一个boolen值。
If isDgSorted
-Do something
else
-Do something
有什么建议吗?
答案 0 :(得分:2)
获取一个值,该值指示DataGridView控件中的项是按升序还是降序排序,还是未排序。
Dim Col1 As DataGridViewColumn = DataGridView1.SortedColumn
'If Col1 is null, then the DataGridView is not currently sorted.
所以你的结果看起来像这样:
If DataGridView1.SortedColumn Is Nothing Then
'Isn't sorted
Else
'It is sorted
End If
有关详细信息,Microsoft会更详细地解释here。
答案 1 :(得分:0)
您可以使用:
Private Sub dataGridView_ColumnHeaderMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs) Handles DataGridView.ColumnHeaderMouseClick
Select Case e.ColumnIndex
Case 0
'handles first column being clicked
Case 1
'handles second column being clicked
Case 3
'handles third column being clicked and so on
End Select
End Sub