Search code examples
vb.netcheckboxdevexpressxtragrid

Dev Express XtraGrid Checkbox


I have a problem with a checkedit in DevExpress XtraGrid control.

I've created unbound column in code (not via wizard), and that checkbox can not be checked by mouse.

Here is my code:

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

Here is the result: screenshot


Solution

  • You should provide data for unbound columns by handling the ColumnView.CustomUnboundColumnData event.
    Here is the demonstration of the ColumnView.CustomUnboundColumnData event usage for read/write scenario (C#):

    //...
    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;
            }
        }
    }