KB Article A2409
Visible to All Users

How to edit all the records in the detail View when a master row's value is changed

Description:
I have an XtraGrid which shows master-detail related data. I have a CheckColumn in the master- and detail View. I wish to check or uncheck (as appropriate) the checkboxes in all the rows belonging to the detail View when the checkbox in the master row is checked or unchecked. How can I do this?

Answer:
The task you need to implement can be divided into several parts:

  1. you need to catch the moment when the checked state of the master row's CheckBox is changed;
  2. you should determine the detail View which corresponds to that master row;
  3. you then need to change the values in the detail view.
    Let us start implementing this task from the beginning.
    To implement the first task we suggest that you handle the master View's ShownEditor event and subscribe to the CheckedChanged event of the in-place editor. BUT: we need to check its type before doing this:
C#
using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; private void gridView1_ShownEditor(object sender, System.EventArgs e) { if((sender as GridView).ActiveEditor is CheckEdit) { CheckEdit edit = (sender as GridView).ActiveEditor as CheckEdit; edit.CheckedChanged += new System.EventHandler(myEdit_CheckedChanged); } }

This approach can be used only if you do not create RepositoryItems specifically for a check column. If you created them, you can simply create the event handler for the repositoryItem's CheckedChanged event and not use this technique.
2) The second task can be implemented using the approach shown in the What can cause the properties, methods, and events of a detail grid view to fail? article.
3) To modify the values in all the detail view rows, you should go through all of them and use one of the approaches described in the Obtaining and Setting Cell Values topic. We have used the SetRowCellValue method in this particular case:

C#
private void myEdit_CheckedChanged(object sender, System.EventArgs e) { UpdateDetailView(gridView1.FocusedRowHandle, (sender as CheckEdit).Checked); } private void UpdateDetailView(int rowHandle, bool state) { GridView dView = gridView1.GetDetailView(rowHandle, 0) as GridView; if(dView != null) for(int i = 0; i < dView.DataRowCount; i++) dView.SetRowCellValue(i, dView.Columns["check"], state); }

SEE ALSO:
How to select rows via an unbound checkbox column

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.