Checking the DevExpress XtraGrid checkbox not registered if focus changes

We have XtraGrid data formats in our Windows form. One of the columns is a check box. The problem is this: when users check the box and click the OK button, the box checked explicitly is not considered a checked grid. When I do this (while looping through the lines):

isAllowed = Convert.ToBoolean(viewMain.GetRowCellValue(nRowCtr, "IsAllowed")) 

I will be back False. BUT, if the user checks the checkbox and then clicks somewhere else on the form or on another line in this grid, diverting focus from the checked checkbox, the same code will return True.

Any understanding of how to fix this behavior would be greatly appreciated.

Workaround: With the default settings, when users click on a cell to edit it, the cell goes into edit mode, loads an editor control (in this case, I have a CheckEdit repository control) and changes the control value (in this case, the checked state). If I click on another row or other control, the cell exits edit mode, fixing the change of the data element. But if I press the button, then my change will be lost. The workaround is to use the CheckEdit CheckedChanged event to close the editor:

 Private Sub edCheck_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles edCheck.CheckedChanged gridYears.FocusedView.CloseEditor() End Sub 
+7
source share
2 answers

This is actually a cleaner way (it works for all RepositoryItems), described in detail on the DevExpress website . The idea is to call the GridView.PostEditor method from the EditValueChanged event handler of the repository object to immediately save the edited value in the grid cell and in the column below.

+10
source

This code in the CellValueChanging event CellValueChanging solved the problem:

 private void OnCellValueChanging(object sender, CellValueChangedEventArgs e) { _gridView.SetFocusedRowCellValue(_gridView.FocusedColumn, e.Value); } 
0
source

All Articles