本文整理汇总了VB.NET中System.Windows.Forms.DataGridView.SortOrder属性的典型用法代码示例。如果您正苦于以下问题:VB.NET DataGridView.SortOrder属性的具体用法?VB.NET DataGridView.SortOrder怎么用?VB.NET DataGridView.SortOrder使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.SortOrder属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1:
Private Sub SortButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles sortButton.Click
' Check which column is selected, otherwise set NewColumn to Nothing.
Dim newColumn As DataGridViewColumn
If dataGridView1.Columns.GetColumnCount(DataGridViewElementStates _
.Selected) = 1 Then
newColumn = dataGridView1.SelectedColumns(0)
Else
newColumn = Nothing
End If
Dim oldColumn As DataGridViewColumn = dataGridView1.SortedColumn
Dim direction As ListSortDirection
' If oldColumn is null, then the DataGridView is not currently sorted.
If oldColumn IsNot Nothing Then
' Sort the same column again, reversing the SortOrder.
If oldColumn Is newColumn AndAlso dataGridView1.SortOrder = _
SortOrder.Ascending Then
direction = ListSortDirection.Descending
Else
' Sort a new column and remove the old SortGlyph.
direction = ListSortDirection.Ascending
oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None
End If
Else
direction = ListSortDirection.Ascending
End If
' If no column has been selected, display an error dialog box.
If newColumn Is Nothing Then
MessageBox.Show("Select a single column and try again.", _
"Error: Invalid Selection", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Else
dataGridView1.Sort(newColumn, direction)
If direction = ListSortDirection.Ascending Then
newColumn.HeaderCell.SortGlyphDirection = SortOrder.Ascending
Else
newColumn.HeaderCell.SortGlyphDirection = SortOrder.Descending
End If
End If
End Sub