读书人

如何让ComboBox选中Items的某一项

发布时间: 2014-01-21 00:35:39 作者: rapoo

怎么让ComboBox选中Items的某一项
我在DataGridView添加了一列ComboBox,并设置了它的DataSource。现在这一列的ComboBox都有了选项,怎么在程序里设置ComboBox选中某一项呢?

((DataGridViewComboBoxCell)row.Cells["DBCol"]).Value = “value”;
这句话没起作用呢?
[解决办法]

DataGridViewComboBoxCell dc=new DataGridViewComboBoxCell();
dc.Items.Add("test1");
dc.Items.Add("test2");
dc.Value = "test2";//这一句

this.dataGridView1.Columns.Add("c1","h1");
this.dataGridView1.Rows.Add();
this.dataGridView1.Rows[0].Cells[0]= dc;

[解决办法]
调试看一下Value是哪一项的的属性。

读书人网 >C#

热点推荐