DataGridTableStyle.AllowSorting Property
Assembly: System.Windows.Forms (in system.windows.forms.dll)
/** @property */ public boolean get_AllowSorting () /** @property */ public void set_AllowSorting (boolean value)
public function get AllowSorting () : boolean public function set AllowSorting (value : boolean)
Not applicable.
Property Value
true if sorting is allowed; otherwise, false. The default is true.When the AllowSorting property is set to true, a triangle appears in each column header indicating the direction of the sort. The user can click on any column header to sort the grid by that column. Clicking the column a second time changes the direction of the sort.
This property overrides the DataGrid.AllowSorting property.
The following code example allows you to toggle sorting availability on a DataGrid by clicking a button and the current sorting status is displayed in a label. This example requires that you have a DataGrid with a System.Data.DataSet that contains some data, a Button and a Label on a Form.
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 void DataGridTableStyleSampleLoad(Object sender, EventArgs e)
{
myDataGridTableStyle1 = new DataGridTableStyle();
mylabel.set_Text("Sorting Status :"
+ System.Convert.ToString(myDataGridTableStyle1.get_AllowSorting()));
if (myDataGridTableStyle1.get_AllowSorting() == true) {
btnApplyStyles.set_Text("Remove Sorting");
}
else {
btnApplyStyles.set_Text("Apply Sorting");
}
// Attach custom event handlers.
myDataGridTableStyle1.add_AllowSortingChanged(
new System.EventHandler(AllowSortingChanged_Handler));
myDataGridTableStyle1.set_MappingName("Customers");
} //DataGridTableStyleSampleLoad
private void AllowSortingChanged_Handler(Object sender, EventArgs e)
{
mylabel.set_Text("Sorting Status :"
+ System.Convert.ToString(myDataGridTableStyle1.get_AllowSorting()));
} //AllowSortingChanged_Handler
private void btnApplyStyles_Click(Object sender, EventArgs e)
{
if (myDataGridTableStyle1.get_AllowSorting() == true) {
// Remove sorting.
myDataGridTableStyle1.set_AllowSorting(false);
btnApplyStyles.set_Text("Allow Sorting");
}
else {
// Allow sorting.
myDataGridTableStyle1.set_AllowSorting(true);
btnApplyStyles.set_Text("Remove Sorting");
}
mylabel.set_Text("Sorting Status :"
+ ((myDataGridTableStyle1.get_AllowSorting()) ? "True" : "False"));
// Add the DataGridTableStyle to DataGrid.
myDataGrid.get_TableStyles().Add(myDataGridTableStyle1);
} //btnApplyStyles_Click
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.