DataGridTableStyle.AllowSorting 屬性

定義

表示當使用這個 DataGridTableStyle 時,是否允許在方格資料表上進行排序。

public:
 property bool AllowSorting { bool get(); void set(bool value); };
public bool AllowSorting { get; set; }
member this.AllowSorting : bool with get, set
Public Property AllowSorting As Boolean

屬性值

Boolean

如果允許排序作業,則為 true,否則為 false。 預設為 true

範例

下列程式碼範例可讓您按一下按鈕來切換 的 DataGrid 排序可用性,而目前的排序狀態會顯示在標籤中。 此範例需要您有 DataGrid ,其中包含一些資料、上的 ButtonLabel FormSystem.Data.DataSet

private:
   void DataGridTableStyle_Sample_Load( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      myDataGridTableStyle1 = gcnew DataGridTableStyle;
      mylabel->Text = String::Concat( "Sorting Status : ", myDataGridTableStyle1->AllowSorting );
      if ( myDataGridTableStyle1->AllowSorting == true )
      {
         btnApplyStyles->Text = "Remove Sorting";
      }
      else
      {
         btnApplyStyles->Text = "Apply Sorting";
      }

      myDataGridTableStyle1->AllowSortingChanged += gcnew System::EventHandler(
         this, &DataGridTableStyle_Sample::AllowSortingChanged_Handler );
      myDataGridTableStyle1->MappingName = "Customers";
   }

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

   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 = String::Concat( "Sorting Status : ", myDataGridTableStyle1->AllowSorting );

      // Add the DataGridTableStyle to DataGrid.
      myDataGrid->TableStyles->Add( myDataGridTableStyle1 );
   }
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);
}
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

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

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

備註

AllowSorting當 屬性設定為 true 時,每個資料行標頭中都會顯示三角形,指出排序的方向。 使用者可以按一下任何資料行標頭,依該資料行排序方格。 再次按一下資料行會變更排序的方向。

這個屬性會 DataGrid.AllowSorting 覆寫 屬性。

適用於

另請參閱