Question

I am programmatically updating my WinForm DataGridView

Problem, DataGridViewCheckBoxCell doesn't get updated !!!

I was google, it seams like knowing case but whatever I've tried did not help yet.

 private void InitializeFunctionsDataGrid()
    {


        System.Data.DataSet ds = func.GetFunctions();



        this.FunctionsDataGrid.DataSource = ds.Tables[0];
        this.FunctionsDataGrid.Columns["FunctionId"].Visible = false;
        this.FunctionsDataGrid.Columns["DESCRIPTION"].Width = 370;


         DataGridViewCheckBoxColumn column = new DataGridViewCheckBoxColumn();
            column.Name = "enable";
            column.HeaderText = "enable";
            column.FalseValue = 0;
            column.TrueValue = 1;
            FunctionsDataGrid.Columns.Add(column);



        foreach(DataGridViewRow row in FunctionsDataGrid.Rows)
        {

                 (( DataGridViewCheckBoxCell)row.Cells["enable"]).Value = 1;

        }

       FunctionsDataGrid.CurrentCell = null;

    }
Was it helpful?

Solution 2

OK basically easiest way for me was to work with datasource. I've add the column to the DataTable and fill it with data. And then last thing this.FunctionsDataGrid.DataSource = ds.Tables[0];

OTHER TIPS

enable is an unbound column. This means that you need to provide cell value yourself.

You can set the VirtualMode property to true and handle the CellValueNeeded event.
If you want to enable the user to check a cell then you need to handle the CellValuePushed event. DataGridView samples that are part of the DataGridView FAQ has a specific example of an unbound checkbox column along with databound columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top