How to set at run time the column type of datagridview

I want to set the DisplayStyle of column 1 in my datagridview to " DropDownButton " with ITEMS collection "A", "B", "C" and "D" at runtime. I also tried to use the code below .. but it didn't work:

 DataGridViewComboBoxCell comboCell = new DataGridViewComboBoxCell();
            comboCell.Items.Add("A");
            comboCell.Items.Add("B");
            comboCell.Value = "A";

 dgv.Columns[1].DefaultCellStyle = comboCell;

      

and this displaystyle should be for columns / rows in datagridview.

Thank,

+3


source to share


1 answer


During the design of your DataGrid, you should leave adding column1. You can add the Comb column at runtime as shown below.



DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
col.Name = "cboColumn";
col.Items.Add("A");
col.Items.Add("B");
dgv.Columns.Add(col);
if (dgv.CurrentRow != null)
    dgv.CurrentRow.Cells[0].Value = "A";

      

+1


source







All Articles