The dev_gridControl_CheckBox column is used to select all and deselected, and all devgridcontrol columns are selected.

Source: Internet
Author: User

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!

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.