The dev_gridControl_CheckBox column is used to select all and deselected, and all devgridcontrol columns are selected.
For more information about the first blog of A cainiao! Provide guidance and advice!
No picture, no truth, as shown below:
To insert a column of checkbox in gridcontrol, and use the checkbox in the header to achieve all the selected and all the unselected results;
After reading a lot of blogs, I finally extracted the desired clear results with refreshing code;
1. Table header implementation:
A data template is used to combine the header text and checkbox:
Code:
<Dxg: GridControl. columns> <dxg: GridColumn FieldName = "select all"> <dxg: GridColumn. headerTemplate> <DataTemplate> <CheckBox IsChecked = "False" Name = "SelectAll" Checked = "SelectAll_Checked" Unchecked = "SelectAll_Unchecked" Content = "select all"> </CheckBox> </DataTemplate> </dxg: gridColumn. headerTemplate> </dxg: GridColumn> </dxg: GridControl. columns>
2. A table in the SQL database of the gridcontrol data source, and set a field named [check] bit to bind this field to the column "select all" in the template set above; the SQL statement is as follows:
DataSet ds = DataUtils. DB. getDataSetFromSQL ("select [ID], [check] All selected, [Solution_Name] solution, [LASTMODIFYUSER] modifier, [LASTMODIFYTIME] modification time from SL_Device_Register_SolutionFlow") gridControl4.ItemsSource = ds. tables [0];
3. All selected and all unselected implementation events: (two events are selected through the header: Checked = "SelectAll_Checked" Unchecked = "SelectAll_Unchecked ".
):The idea is to traverse every checkbox row in gridcontrol. The Code is as follows:
Private void SelectAll_Checked (object sender, RoutedEventArgs e) {DataTable dt = (DataTable) gridControl6.ItemsSource; int rowsCount = dt. rows. count; for (int I = 0; I <rowsCount; I ++) {string value = dt. rows [I] ["select all"]. toString (); value = "True"; dt. rows [I] ["select all"] = value;} private void SelectAll_Unchecked (object sender, RoutedEventArgs e) {DataTable dt = (DataTable) gridControl6.ItemsSource; int rowsCount = dt. rows. count; for (int I = 0; I <rowsCount; I ++) {string value = dt. rows [I] ["select all"]. toString (); value = "false"; dt. rows [I] ["select all"] = value ;}}
In this way, we want to achieve the effect shown in the figure!
Please kindly advise!