开发者

Using DataGridViewComboBoxColumn and DataGridViewComboBoxCell

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.

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" }; 

Thanks

Nir


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");


I spent some time trying to track down something similar. Turns out you can't edit cells (ie. select items from a ComboBox) if you've got FullRowSelect turned on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜