Winforms – Set value for same cell in “DevExpress XtraGrid CellValueChanging” event

devexpressgridviewwinforms

I have a XtraGrid with one GridView, with a column with checkbox repository item. Now I am handling the CellValueChanging event because I want to only allow the user to check or uncheck based on calculations on other column values on the same row hence I need the e.RowHandle and e.Column of this event and this cannot be done on the EditValueChanging of the repository control.

Now somewhere my calculations say that user cannot check a particular cell to and I throw a message box and try Me.BandedGridView1.SetRowCellValue(e.RowHandle, e.Column, False) but unfortunately this does not set the value to false of that cell.

I need to do it here and here only because of the huge number of calculations based on other column values and I need to set value of the current cell whose event I'm handling right.

Please help.

I'm using DevExpress 9.2 (no chance of upgrading to higher version)

Best Answer

Try this code it's working perfectly !

private void GridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
{
    if (e.Column.Caption != "yourColumnCaption") return;
       GridView1.SetFocusedRowCellValue("yourColumnFieldName", 1);
}