读书人

C# winform中datagridview的下拉框如何

发布时间: 2013-04-23 18:56:14 作者: rapoo

C# winform中datagridview的下拉框怎么用,如何绑定List数据源
本人返回结果集为:

List<KeyValuePair<string, string>> list;

我将datatable传入子窗口,并绑定到datagridview中,然后要把单元格转换成下拉框的形式,并且将list数据源绑定到下拉框,求大神指点!
[解决办法]

((DataGridViewComboBoxCell)dgvStudentList.Rows[0].Cells["Student"]).DataSource = list;
((DataGridViewComboBoxCell)dgvStudentList.Rows[0].Cells["Student"]).ValueMember = "StuNum";
((DataGridViewComboBoxCell)dgvStudentList.Rows[0].Cells["Student"]).DisplayMember = "StuName";

[解决办法]
引用:
((DataGridViewComboBoxCell)dgvStudentList.Rows[0].Cells["Student"]).DataSource = list;
((DataGridViewComboBoxCell)dgvStudentList.Rows[0].Cells["Student"]).ValueMember = "StuNum";
((DataGridViewCombo……


这个就可以啊, 你类型无法转换, 说明你选择的那个 CELL 不是 Combobox 列

读书人网 >C#

热点推荐