DevExpress Grid, Bool rows change not reflect immediatly

廉价感情. 提交于 2019-12-13 05:24:47

问题


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 ?


回答1:


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);
}



回答2:


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);
}


来源:https://stackoverflow.com/questions/34924344/devexpress-grid-bool-rows-change-not-reflect-immediatly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!