C# DataSet CheckBox Column With DevExpress DataGrid

16,637

Solution 1

Why do you use a Checkbox column in your DataSet ?

You should try adding a bool column in your DataSet, when binding the DataSet to the grid, it will automatically use a Checkbox to display the item value.

Solution 2

When you dont have a bool column in your datatable you can also manually/in code set the editor for the column.

Example in code:
Say you add a devex grid column called "fCol". The value for checked = "YES", unchecked = "NONO";

        GridColumn fCol = gridView1.Columns.Add();
        RepositoryItemCheckEdit fCheckEdit = new RepositoryItemCheckEdit();
        fCheckEdit.ValueChecked = "YES";
        fCheckEdit.ValueUnchecked = "NONO";
        fCol.ColumnEdit = fCheckEdit;
        fCol.FieldName = "Haganise";

Of course you can also do this in the designer.

Share:
16,637
cheunology
Author by

cheunology

Updated on June 05, 2022

Comments

  • cheunology
    cheunology almost 2 years

    Scenario

    I have a DevExpress DataGrid which is bound to a DataSet in C#. I want to populate each dataset row to contain a string in the first column and a checkbox in the second. My code below doesn't work quite how I want it to, and I'm not sure why.....

    The Code

    As you can see I've declared a dataset, but when I try and pass in a new checkbox object to the 2nd column it just displays the system name for the checkbox.

            DataSet prodTypeDS = new Dataset();
            DataTable prodTypeDT = prodTypeDS.Tables.Add();
            prodTypeDT.Columns.Add("MurexID", typeof(string));
            prodTypeDT.Columns.Add("Haganise",typeof(CheckBox));
    
            //WHY DOES THIS NOT WORK? 
            //(Displays "System.Windows.Forms.CheckBox, CheckState: 0")
            //Instead of a checkbox.
            CheckBox c = new CheckBox();
            prodTypeDS.Tables[0].Rows.Add("Test",c);
            //This doesn't work either....
            prodTypeDS.Tables[0].Rows.Add("Test",c.CheckState);
    

    ......I hope this is just because it's a DevExpress datagrid....

  • Miha Markic
    Miha Markic about 14 years
    True, OP should use typeof(bool) column.