DataGridView.SortOrder プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


このプロパティを使用して、SortedColumn プロパティで指定された列に Automatic の SortMode プロパティ値が設定されている場合に表示される並べ替えグリフを判断します。列に Programmatic の SortMode プロパティ値が設定されている場合は、SortGlyphDirection プロパティを使用して、並べ替えグリフの表示および非表示を自分で設定する必要があります。列に NotSortable の SortMode プロパティ値が設定されている場合、並べ替えグリフを表示できますが、列が自動的にサイズ変更される場合、領域は指定されません。
![]() |
---|
カスタム並べ替えを使用してコントロールを並べ替える場合、このプロパティの値は無効です。カスタム並べ替えの詳細については、Sort メソッドおよび SortCompare イベントのトピックを参照してください。 |

プログラムによる並べ替えで SortOrder プロパティを使用する方法を示すコード例を次に示します。
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 Not oldColumn Is 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
private void sortButton_Click(object sender, System.EventArgs e) { // Check which column is selected, otherwise set NewColumn to null. DataGridViewColumn newColumn = dataGridView1.Columns.GetColumnCount( DataGridViewElementStates.Selected) == 1 ? dataGridView1.SelectedColumns[0] : null; DataGridViewColumn oldColumn = dataGridView1.SortedColumn; ListSortDirection direction; // If oldColumn is null, then the DataGridView is not currently sorted. if (oldColumn != null) { // Sort the same column again, reversing the SortOrder. if (oldColumn == newColumn && dataGridView1.SortOrder == SortOrder.Ascending) { direction = ListSortDirection.Descending; } else { // Sort a new column and remove the old SortGlyph. direction = ListSortDirection.Ascending; oldColumn.HeaderCell.SortGlyphDirection = SortOrder.None; } } else { direction = ListSortDirection.Ascending; } // If no column has been selected, display an error dialog box. if (newColumn == null) { MessageBox.Show("Select a single column and try again." , "Error: Invalid Selection", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { dataGridView1.Sort(newColumn, direction); newColumn.HeaderCell.SortGlyphDirection = direction == ListSortDirection.Ascending ? SortOrder.Ascending : SortOrder.Descending; } }

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
その他の技術情報
DataGridView コントロール (Windows フォーム)
Weblioに収録されているすべての辞書からDataGridView.SortOrder プロパティを検索する場合は、下記のリンクをクリックしてください。

- DataGridView.SortOrder プロパティのページへのリンク