在wpf中检查DevExpress的DataGrid控件的复选框列的事件

时间:2013-07-23 11:51:56

标签: wpf devexpress

我想在wpf中对DevExpress的DataGrid控件的复选框列的Checked Event执行一些任务。

1 个答案:

答案 0 :(得分:1)

要跟踪相应布尔列的值何时更改,我建议您处理TabbedView.CellValueChanged事件:

((TableView)gridControl.View).CellValueChanged += MainWindow_CellValueChanged
//...
void MainWindow_CellValueChanged(object sender, CellValueChangedEventArgs e) {
    if(e.Column.FieldName == "BooleanProp") { 
        // do something
    }
}

要直接在单元格编辑器上跟踪Checked / Unchecked事件,您可以使用以下方法:

((TableView)gridControl.View).ShownEditor += TableView_ShownEditor;
((TableView)gridControl.View).HiddenEditor += TableView_HiddenEditor;
//...

void TableView_ShownEditor(object sender, EditorEventArgs e) {
    if(e.Column.FieldName == "BooleanProp") {
        ((DevExpress.Xpf.Editors.CheckEdit)e.Editor).Checked += BooleanPropCheckEdit_Checked;
        ((DevExpress.Xpf.Editors.CheckEdit)e.Editor).Unchecked += BooleanPropCheckEdit_Unchecked;
    }
}
void TableView_HiddenEditor(object sender, EditorEventArgs e) {
    if(e.Column.FieldName == "BooleanProp") {
        ((DevExpress.Xpf.Editors.CheckEdit)e.Editor).Checked -= BooleanPropCheckEdit_Checked;
        ((DevExpress.Xpf.Editors.CheckEdit)e.Editor).Unchecked -= BooleanPropCheckEdit_Unchecked;
    }
}
void BooleanPropCheckEdit_Checked(object sender, RoutedEventArgs e) {
    // do something
}
void BooleanPropCheckEdit_Unchecked(object sender, RoutedEventArgs e) {
    // do something
}