tags:

views:

22

answers:

2

Hi,

In my application i have datagrid with simple type of cells - string, integer.

I want to change one of the cell from string to be combobox.

i try to populate the in each line different inomration, but did not see anything. It means that i see comboBox in each cell of the column but the comboBox is empty.

enter code here


DataGridViewComboBoxColumn cmdParam1 = new DataGridViewComboBoxColumn();
cmdParam1.Name = "cmdParam1";
cmdParam1.HeaderText = "cmdParam1";
dataGridView1.Columns.Add(cmdParam1);

DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell)    (dataGridView1.Rows[2].Cells["cmdParam1"]);
cell.DataSource = new string[] { "1", "2", "3" }; 

cell = (DataGridViewComboBoxCell)(dataGridView1.Rows[4].Cells["cmdParam1"]);
cell.DataSource = new string[] { "4", "5", "6" }; 

enter code here

Thanks

Nir

A: 

Instead of assiging string array to datasource try below code:

DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) (dataGridView1.Rows[2].Cells["cmdParam1"]);
            cell.Items.Add("1");
            cell.Items.Add("2");
            cell.Items.Add("3");


DataGridViewComboBoxCell cell = (DataGridViewComboBoxCell) (dataGridView1.Rows[4].Cells["cmdParam1"]);
            cell.Items.Add("4");
            cell.Items.Add("5");
            cell.Items.Add("6");
vinayak
A: 

Hi and thanks but it did not fix it.

The the comboBox stayed empty ( i try to attach figure but did not succeed since i new user here)

i think that maybe i have some problems with one of the properties in DatGridView ?!

thanks

Nir

nirselickter