Hi all!
I have DataGridView whose sourse I set to a datatable with 4 columns
containing data. I then remove a column, create a DataGridViewComboBoxColumn and insert this into the same location as the column that was removed. I want to set as the selected value in the combo box of every cell in the DataGridView a specific value I have stored in the column of the datable that I removed in the DataGridView.
How can I set a value in a cell of the DataGridView that contains a DataGridViewComboBoxColumn?
Thanks for your help,
~~Elvia
Loading
Elvia GonzalezPosted May 4, 2006, 8:34 PM
Hi,
I have been debugging my windows application. I have found that the code in the previous post is working as I expected, because I see the variable in the Watch window.
I have the code of the previous post in the Load() method of the form class (FrmTestCases.cs) that has my DataGridView.
But when the debugger leaves the file that has this code (FrmTestCases.cs) to return to the file that called this code (FrmExplorer.cs), the value that I set in that cell by the code is lost and set automatically to null.
When the value was lost I set it in this watch window and the ComboxBox selected the value I set.
I don't know whether the problem is because I removed and then added this column (see the first post). At the end of the Load() method I have this line: dataGridView.AutoGenerateColumns = false; if I don't use it, the column that I removed appears again. Any idea about why the value of the DataGridComboBoxColumn is changed to null automatically and how to solve it?
Best Regards,
Elvia
Elvia GonzalezPosted May 4, 2006, 2:00 PM
Hi everybody!
I have added items to the DataGridViewComboBoxColumn and the value that I want to set is one of the values in the items list. This is my code:
DataGridViewComboBoxColumn cb = new DataGridViewComboBoxColumn();
cb = CreateComboBoxColumn("Category");
cb.Items.AddRange(new string[] { "Mr.", "Ms.", "Mrs.", "Dr." });
dataGridView.Columns.Insert(1, cb);
dataGridView.Rows[0].Cells[1].Value = "Mr.";
I want to see as the selected value in the combobox “Mr.”. Once I load the form the combobox doesn’t show a selected value. I have to drop the combobox to see the items.
Any suggestion is very welcome,
ElviaElvia GonzalezPosted May 3, 2006, 5:48 PM
I tried dataGridView1.Rows["RowName"].Cells["ColumnName"].Value = "1"; but it doesn’t work.