I have a DataGridView in my Windows Form with 3 forms. The first 2 columns are uneditable, and the last column should be editable. Only some cells in Column #3 are set to combo boxes (they are of type DataGridViewComboBoxCell). Because not all cells in Column #3 are combo boxes, is there a way to individually invoke this dropdown in these cells? Right now I can only see a way to do this on a whole column, but not all cells in column #3 are comboboxes. In my example below, if the content in column #2 says "Cell that requires combobox", then the cell in column #3 in that row should be a ComboBoxCell. Otherwise, it should just be an editable text cell. The code looks something like this:
Column 1 | Column 2 | Column 3
ex 1 | Cell that requires combobox | [editable textbox]
ex 2 | Cell that doesn't require combobox | [combobox dropdown]
DataGridView newdatagridview = new DataGridView();
var column1 = new DataGridViewTextBoxCell();
var column2 = new DataGridViewTextBoxCell();
var column3 = new DataGridViewComboBoxCell();
var row = new DataGridViewRow();
column1.Value = "ex1";
column2.Value = "ex2";
column3.Value = column2.Value;
row.Cells.Add(column1);
row.Cells.Add(column2);
if (column2.Value == "Cell that requires combobox") {
// add options for the dropdown
column3.Items.Add("0");
column3.Items.Add("1");
column3.Items.Add("2");
column3.Items.Add("3");
column3.Items.Add("4");
//column3.ReadOnly = false; <- This didn't work
row.Cells.Add(column3); //You only add a combocell if column2's value says "Cell that requires combobox"
}
newdatagridview.Rows.Add(row);