hi
i have a WinForm with DataGridViewControll.

one of the datagrid columns is a DataGridViewCheckBoxColumn.

how can i Check or uncheck the Checkbox column of a certain row ?

Recommended Answers

All 2 Replies

In this example, the CellValueChanged event is used to examine the cell when the value is changed. For your question, extract the code you need and just substitute the row and column indexes to refer to the known cell, which will allow you to "get" or "set" the Value property to be true or false (checked or unchecked).

// Occurs when the value is changed...
                private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e)
                {
                    int iCol = e.ColumnIndex;
                    int iRow = e.RowIndex;
                    if (iRow > -1 & iCol > -1)
                    {
                        if (dataGridView1.Rows[iRow].Cells[iCol].ValueType == typeof(bool))
                        {
                            bool bChecked = (bool)dataGridView1.Rows[iRow].Cells[iCol].Value;
                        }
                    }
                }

thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.