我如何理解datagridview是否排序?

时间:2013-07-16 11:09:25

标签: vb.net sorting datagridview

如何确定DataGridView是否已排序?我需要获得一个boolen值。

If isDgSorted
 -Do something
else
 -Do something

有什么建议吗?

2 个答案:

答案 0 :(得分:2)

DataGridView.SortOrder属性

获取一个值,该值指示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