DevExpress Grid, Bool rows change not reflect imme

2019-08-29 05:06发布

I have a DX grid view and it has 2 bool columns. My purpose is when I check for ex 2nd row in column1, column2 2nd must be changed immediatly, but not. It changes after clicking another row. Here is my rowcellvaluechanged event code :

 void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
    {
        //button1.PerformClick();
        if (e.Column.Name == "col1")
        {
             var x = gridView1.GetRowCellValue(e.RowHandler, col1);
            gridView1.SetRowCellValue(e.RowHandler, col2, x);
        }

    }

I looked for in DX website and there is no solution. How can I handle on it ?

2条回答
爷的心禁止访问
2楼-- · 2019-08-29 05:28

You can use the GridView.PostEditor method to immediately pass the changed value from the editor into the Grid's underlying data source. The best place for doing this is the EditValueChanged event of real cell editor. You can handle this event as follows:

gridView1.PopulateColumns();
var checkEdit = gridView1.Columns["Value1"].RealColumnEdit as RepositoryItemCheckEdit;
checkEdit.EditValueChanged += checkEdit_EditValueChanged;
//...
void checkEdit_EditValueChanged(object sender, EventArgs e) {
    gridView1.PostEditor();
}

Then you can implement all needed dependencies:

gridView1.CellValueChanged += gridView1_CellValueChanged;
//...
void gridView1_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e) {
    if(e.Column.FieldName == "Value1") 
        gridView1.SetRowCellValue(e.RowHandle, gridView1.Columns["Value2"], e.Value);
}
查看更多
地球回转人心会变
3楼-- · 2019-08-29 05:36

The Grid posts an editor value when you switch to another cell. To force it, call the PostEditor method. But, in this case, you will need to use the EditValueChanged event of the active editor. To get it, use the ActiveEditor property. To catch the moment, when an editor is created, use the ShownEditor event.

gridView1.ShownEditor += gridView1_ShownEditor;

private void gridView1_ShownEditor(object sender, EventArgs e) {
    GridView view = (GridView)sender;
    view.ActiveEditor.EditValueChanged += editor_EditValueChanged;
}

private void editor_EditValueChanged(object sender, EventArgs e) {
    if (!gridView1.FocusedColumn.Name == "col1")
        return;
    gridView1.PostEditor();
    var x = gridView1.GetRowCellValue(e.RowHandler, col1);
    gridView1.SetRowCellValue(e.RowHandler, col2, x);
}
查看更多
登录 后发表回答