Dev Express XtraGrid复选框

时间:2013-10-11 16:37:50

标签: vb.net checkbox devexpress xtragrid

我在DevExpress XtraGrid控件中检查了一个问题。

我在代码中创建了未绑定列(不是通过向导),鼠标无法检查该复选框。

这是我的代码:

Private Sub DataViewFrm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim data As New DataTable
    data=getDataTable("select....")

    gridViewer.DataSource = data

    Dim Tick As New RepositoryItemCheckEdit()

    gridViewer.Refresh()

    Dim unbColumn As GridColumn = gridvwViewer.Columns.AddField("Coba")
    unbColumn.VisibleIndex = gridvwViewer.Columns.Count
    unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Boolean
    unbColumn.OptionsColumn.AllowEdit = True
    unbColumn.OptionsColumn.ReadOnly = False

    gridvwViewer.Columns(8).ColumnEdit = Tick     
End Sub

结果如下:screenshot

1 个答案:

答案 0 :(得分:2)

您应该通过处理ColumnView.CustomUnboundColumnData事件来提供未绑定列的数据 以下是对读/写方案(C#)的ColumnView.CustomUnboundColumnData事件使用情况的演示:

//...
var unbColumn = gridView1.Columns.AddField("Coba");
unbColumn.VisibleIndex = gridView1.Columns.Count;
unbColumn.UnboundType = DevExpress.Data.UnboundColumnType.Boolean;
CobaValues = new Dictionary<int, bool>();
gridView1.CustomUnboundColumnData += gridView1_CustomUnboundColumnData;

//...
IDictionary<int, bool> CobaValues;
void gridView1_CustomUnboundColumnData(object sender, CustomColumnDataEventArgs e) {
    if(e.Column.FieldName == "Coba") {
        if(e.IsGetData) {
            bool value;
            if(CobaValues.TryGetValue(e.ListSourceRowIndex, out value))
                e.Value = value;
        }
        if(e.IsSetData) {
            CobaValues[e.ListSourceRowIndex] = (bool)e.Value;
        }
    }
}