Disabling some row of DataGridViewComboBoxColumn and DataGridViewButtonColumn
I'd like to disable both the DGVComboBoxColumn and DGVButtonColumn in some row, but i don't know what code i have to use..
[CODE] private void PopulateDataGridView() { for (int i = 0; i < itemCount; i++) { //if "Unit" is null, then the quantity and waste are null if (item[i, 2] == "") { dgvTakeOff.Rows.Add(item[i, 0], item[i, 1], item[i, 2], null, null);//, "NULL", "NULL"); //I WANT TO DISABLE THE "_Properties" (DGVComboBoxColumn) HERE!! //I ALSO WANT TO DISABLE THE "_Button" (DGVButtonColumn) HERE!! } //else if "unit" is not null, then the quantity and waster is zero out else { dgvTakeOff.Rows.Add(item[i, 0], item[i, 1], item[i, 2], "0", "0");//, "Dictionary??", "OK"); } } _Properties.Items.Add("Footing"); _Properties.Items.Add("Wall"); _Properties.Items.Add("Whatever else is here!!"); } [\CODE]
I've marked the place i want to use it above in the code area..
somepenguin Wednesday, July 22, 2009 8:25 PM
Hi somepenguin,
I am afraid DataGridViewComboBoxColumn and DataGridViewButtonColumn won't meet your needs. While DataGridViewComboBoxCell and DataGridViewButtonCell are suitable for this requirement. Please look at the following code: DataGridViewButtonCell dgvBtnCell = new DataGridViewButtonCell(); dataGridView1[0, 0] = dgvBtnCell;
DataGridViewComboBoxCell dgvCmbCell = new DataGridViewComboBoxCell(); dgvCmbCell.Items.Add("Item1"); dgvCmbCell.Items.Add("Item2"); dgvCmbCell.Items.Add("Item3");
dataGridView1[1, 0] = dgvCmbCell;
The code only set the first row of dataGridView1's cell one for Button and another for ComboBox.
Hope this help.
Sincerely, Kira QianPlease mark the replies as answers if they help and unmark if they don't.
If disabling means , making it readonly then dgvTakeOff.Rows[dgvTakeOff.Rows.Count-1].Cells[/*DGVComboBoxColumn*/].ReadOnly =True; dgvTakeOff.Rows[dgvTakeOff.Rows.Count-1].Cells[/*DGVButtonColumn*/].ReadOnly =True;
NareshG Thursday, July 23, 2009 4:32 AM
Hi somepenguin,
I am afraid DataGridViewComboBoxColumn and DataGridViewButtonColumn won't meet your needs. While DataGridViewComboBoxCell and DataGridViewButtonCell are suitable for this requirement. Please look at the following code: DataGridViewButtonCell dgvBtnCell = new DataGridViewButtonCell(); dataGridView1[0, 0] = dgvBtnCell;
DataGridViewComboBoxCell dgvCmbCell = new DataGridViewComboBoxCell(); dgvCmbCell.Items.Add("Item1"); dgvCmbCell.Items.Add("Item2"); dgvCmbCell.Items.Add("Item3");
dataGridView1[1, 0] = dgvCmbCell;
The code only set the first row of dataGridView1's cell one for Button and another for ComboBox.
Hope this help.
Sincerely, Kira QianPlease mark the replies as answers if they help and unmark if they don't.