DataGridTableStyle.AllowSorting Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Indica se l'esecuzione dell'ordinamento della tabella della griglia è consentita quando si usa questo oggetto 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
Valore della proprietà
true
se è consentita l'esecuzione dell'ordinamento, in caso contrario, false
. Il valore predefinito è true
.
Esempio
L'esempio di codice seguente consente di attivare o disattivare la disponibilità di ordinamento in un DataGrid oggetto facendo clic su un pulsante e lo stato di ordinamento corrente viene visualizzato in un'etichetta. In questo esempio è necessario disporre di un oggetto con un DataGrid System.Data.DataSet oggetto che contiene alcuni dati, un Button oggetto e un oggetto Label in un oggetto Form.
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
Commenti
Quando la AllowSorting proprietà è impostata su true
, viene visualizzato un triangolo in ogni intestazione di colonna che indica la direzione dell'ordinamento. L'utente può fare clic su qualsiasi intestazione di colonna per ordinare la griglia in base a tale colonna. Facendo clic sulla colonna una seconda volta viene modificata la direzione dell'ordinamento.
Questa proprietà esegue l'override della DataGrid.AllowSorting proprietà .