次の方法で共有


DataGridTableStyle.AllowSorting プロパティ

DataGridTableStyle を使用する場合に、グリッド テーブルで並べ替えを実行できるかどうかを示します。

Public Property AllowSorting As Boolean
[C#]
public bool AllowSorting {get; set;}
[C++]
public: __property bool get_AllowSorting();public: __property void set_AllowSorting(bool);
[JScript]
public function get AllowSorting() : Boolean;public function set AllowSorting(Boolean);

プロパティ値

並べ替えを実行できる場合は true 。それ以外の場合は false 。既定値は true です。

解説

AllowSorting プロパテイが true に設定されている場合、各列ヘッダーに並べ替えの方向を示す三角形が表示されます。いずれかの列ヘッダーをクリックすると、その列を基準としてグリッドを並べ替えることができます。同じ列をもう一度クリックすると、並べ替えの方向が変わります。

使用例

[Visual Basic, C#, C++] ボタンをクリックすることによって DataGrid 上で並べ替えを実行できるようにし、現在の並べ替えの状態をラベルに表示する例を次に示します。この例は、データを格納する System.Data.DataSet を持つ DataGridButton 、および Label が、 Form 上にあることを前提としています。

 
Private Sub DataGridTableStyle_Sample_Load(ByVal sender As Object, _
                        ByVal e As EventArgs) Handles MyBase.Load
   myDataGridTableStyle1 = New DataGridTableStyle()

   mylabel.Text = "Sorting Status :" + myDataGridTableStyle1.AllowSorting.ToString()
   If myDataGridTableStyle1.AllowSorting = True Then
      btnApplyStyles.Text = "Remove Sorting"
   Else
      btnApplyStyles.Text = "Apply Sorting"
   End If
   ' Attach custom event handlers.
   AddHandler myDataGridTableStyle1.AllowSortingChanged, AddressOf AllowSortingChanged_Handler
   myDataGridTableStyle1.MappingName = "Customers"
End Sub 'DataGridTableStyle_Sample_Load

Private Sub AllowSortingChanged_Handler(ByVal sender As Object, ByVal e As EventArgs)
   mylabel.Text = "Sorting Status :" + myDataGridTableStyle1.AllowSorting.ToString()
End Sub 'AllowSortingChanged_Handler

Private Sub btnApplyStyles_Click(ByVal sender As Object, _
                                 ByVal e As EventArgs) Handles btnApplyStyles.Click
   If myDataGridTableStyle1.AllowSorting = True Then
      ' Remove sorting.
      myDataGridTableStyle1.AllowSorting = False
      btnApplyStyles.Text = "Allow Sorting"
   Else
      ' Allow sorting.
      myDataGridTableStyle1.AllowSorting = True
      btnApplyStyles.Text = "Remove Sorting"
   End If

   mylabel.Text = "Sorting Status :" + myDataGridTableStyle1.AllowSorting.ToString
   ' Add the DataGridTableStyle to DataGrid.
   myDataGrid.TableStyles.Add(myDataGridTableStyle1)
End Sub 'btnApplyStyles_Click

[C#] 
private void DataGridTableStyle_Sample_Load(object sender,
                                       EventArgs e)
{
   myDataGridTableStyle1 = new DataGridTableStyle();

   mylabel.Text = "Sorting Status :" + 
         myDataGridTableStyle1.AllowSorting.ToString();
   if(myDataGridTableStyle1.AllowSorting == true)
   {
      btnApplyStyles.Text = "Remove Sorting";
   }
   else
   {
      btnApplyStyles.Text = "Apply Sorting";
   }
   // Attach custom event handlers.
   myDataGridTableStyle1.AllowSortingChanged += 
               new System.EventHandler(AllowSortingChanged_Handler);
   myDataGridTableStyle1.MappingName = "Customers";
} 
private void AllowSortingChanged_Handler(object sender,EventArgs e)
{         
   mylabel.Text = "Sorting Status :" 
         + myDataGridTableStyle1.AllowSorting.ToString();
}     
private void btnApplyStyles_Click(object sender, EventArgs e)
{       

   if(myDataGridTableStyle1.AllowSorting == true)
   {            
      // Remove sorting.
      myDataGridTableStyle1.AllowSorting = false; 
      btnApplyStyles.Text = "Allow Sorting";
   }
   else
   {
      // Allow sorting.
      myDataGridTableStyle1.AllowSorting = true;
      btnApplyStyles.Text = "Remove Sorting";
   } 

   mylabel.Text = "Sorting Status :" + myDataGridTableStyle1.AllowSorting;
   // Add the DataGridTableStyle to DataGrid.
   myDataGrid.TableStyles.Add(myDataGridTableStyle1);
}

[C++] 
private:
    void DataGridTableStyle_Sample_Load(Object* /*sender*/,
        EventArgs* /*e*/) {
            myDataGridTableStyle1 = new DataGridTableStyle();

            mylabel->Text = String::Concat(S"Sorting Status : ", 
                __box(myDataGridTableStyle1->AllowSorting));
            if (myDataGridTableStyle1->AllowSorting == true) {
                btnApplyStyles->Text = S"Remove Sorting";
            } else {
                btnApplyStyles->Text = S"Apply Sorting";
            }
            // Attach custom event handlers.
            myDataGridTableStyle1->AllowSortingChanged += 
                new System::EventHandler(this, &DataGridTableStyle_Sample::AllowSortingChanged_Handler);
            myDataGridTableStyle1->MappingName = S"Customers";
        }

        void AllowSortingChanged_Handler(Object* /*sender*/, 
            EventArgs* /*e*/) {
            mylabel->Text = String::Concat(S"Sorting Status : ",
                __box( myDataGridTableStyle1->AllowSorting));
        }

        void btnApplyStyles_Click(Object* /*sender*/, EventArgs* /*e*/) {

            if (myDataGridTableStyle1->AllowSorting == true) {
                // Remove sorting.
                myDataGridTableStyle1->AllowSorting = false;
                btnApplyStyles->Text = S"Allow Sorting";
            } else {
                // Allow sorting.
                myDataGridTableStyle1->AllowSorting = true;
                btnApplyStyles->Text = S"Remove Sorting";
            }

            mylabel->Text = String::Concat(S"Sorting Status : ", 
                __box(myDataGridTableStyle1->AllowSorting));
            // Add the DataGridTableStyle to DataGrid.
            myDataGrid->TableStyles->Add(myDataGridTableStyle1);
        }

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

DataGridTableStyle クラス | DataGridTableStyle メンバ | System.Windows.Forms 名前空間 | AllowSortingChanged