2

I'm using DevExpress GridControl, where I have data binded and one column contains boolean flag IsOrdered. I registered for the event on my SimpleGridView called CellValueChanged because when my check field (meaning the IsOrdered value) is changed I want to perform some actions. In the subscriber method I check if (e.Column.FieldName == "IsOrdered") and then I perform these operations.

The problem is that that CellValueChanged event is raised not until I check the checkbox (by double-click) and click somewhere else. That unfortunately causes an annoying problem here: for example when I have my row in that grid which has IsOrdered set to false (not selected), and I check this checkbox and immediatelly uncheck it and then I click somewhere else, the event is also raised. As I think that event should not be raised in such a case, because that IsOrdered value wasn't actually changed (it was false, then true, and finally false again).

Maybe there is some way to change this default behavior ? What would be perfect is to have CellValueChanged event raised immediately after checkbox is checked/unckecked, not having to click somewhere else the checkbox to have the event raised.

There is also a event called CellValueChanging, but it does not resolve my problem, because that event is raised actually before the IsOrdered's value is changed, but in my subscriber method I need to know if that field's value is changed to true or false.

I will appreciate any help :).

Dawid Sibiński
  • 1,657
  • 3
  • 21
  • 40

2 Answers2

1

You can use GridView.CellValueChanging event and in this event you can change field's value by using ColumnView.SetRowCellValue method.
Here is example:

private void gridView1_CellValueChanging(object sender, CellValueChangedEventArgs e)
{
    if (e.Column.FieldName == "IsOrdered")
    {
        gridView1.SetRowCellValue(e.RowHandle, e.Column, e.Value);

        //Do your other staff here.               
    }
}
nempoBu4
  • 6,521
  • 8
  • 35
  • 40
0

You should use CheckEdit repository item inside the grid for that to work.

As stated on the help: The editors of the DevExpress Editors Library can be used to perform in-place editing in the container controls provided by DevExpress. This topic describes the mechanism used to assign in-place editors to container controls.

You may also look at this question which states that "You should call the GridView.PostEditor method from a repository item's EditValueChanged event handler to immediately save the edited value to the grid's cell and the underlying column."

Turker Tunali
  • 377
  • 2
  • 11
  • Thanks, it's actually fine, because I get the actual value for which the checkbox is changed, but the other problem there is that I cannot get the selected row from my GridView in that case, so I cannot perform any oprations on my object, which is actually the row in which the checkbox value is changed. – Dawid Sibiński May 08 '15 at 12:48
  • Have you consider using GetFocusedRow to get the selected row ? – Turker Tunali May 08 '15 at 12:54