DataGridViewColumnHeaderCell.SortGlyphDirection プロパティとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewColumnHeaderCell.SortGlyphDirection プロパティの意味・解説 

DataGridViewColumnHeaderCell.SortGlyphDirection プロパティ

メモ : このプロパティは、.NET Framework version 2.0新しく追加されたものです。

表示されている並べ替えグリフを示す値を取得または設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Property SortGlyphDirection As
 SortOrder
Dim instance As DataGridViewColumnHeaderCell
Dim value As SortOrder

value = instance.SortGlyphDirection

instance.SortGlyphDirection = value
public SortOrder SortGlyphDirection { get;
 set; }
public:
property SortOrder SortGlyphDirection {
    SortOrder get ();
    void set (SortOrder value);
}
/** @property */
public SortOrder get_SortGlyphDirection ()

/** @property */
public void set_SortGlyphDirection (SortOrder
 value)
public function get SortGlyphDirection
 () : SortOrder

public function set SortGlyphDirection
 (value : SortOrder)

プロパティ
現在のグリフを表す SortOrder 値。既定値は None です。

例外例外
例外種類条件

InvalidEnumArgumentException

このプロパティ設定時に指定された値が、有効な SortOrder 値ではありません。

InvalidOperationException

このプロパティ設定時にセルの OwningColumn プロパティまたは DataGridView プロパティいずれかの値が null 参照 (Visual Basic では Nothing) です。

または

このプロパティの値の変更時に指定された値が None ではなく所有している列の SortMode プロパティの値が NotSortable です。

解説解説

このプロパティは、SortMode プロパティが DataGridViewColumnSortMode.Automatic に設定されている列については、自動的に設定されます。SortMode プロパティが DataGridViewColumnSortMode.Programmatic に設定されている列を基準にして並べ替えを行う場合は、このプロパティ手動設定する必要があります

使用例使用例

次のコード例では、プログラム上の並べ替えSortGlyphDirection プロパティ使用する方法示します

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;
    }
}
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewColumnHeaderCell クラス
DataGridViewColumnHeaderCell メンバ
System.Windows.Forms 名前空間
DataGridView クラス
SortOrder
DataGridViewColumn.SortMode プロパティ



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「DataGridViewColumnHeaderCell.SortGlyphDirection プロパティ」の関連用語

DataGridViewColumnHeaderCell.SortGlyphDirection プロパティのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridViewColumnHeaderCell.SortGlyphDirection プロパティのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS