问题描述
我想使用List< bindentity>绑定到DataGridViewComboBoxColumn作为自定义数据源。但是当ui show.i获取错误消息时,它总是会发生数据错误,它是关于单元格值非法的。
我该怎么办?
代码列表如下:
enum ComStationType {PCPSYS,ESPSYS ...}
class BindEntity
{
公共字符串名称{get}
公共对象价值{get}
}
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
dgvc.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dgvc.DataPropertyName =column1 ;
dgvc.DataSource = GetComStationTypeInfo(); // GetComStationTypeInfo()返回List< bindentity>为了绑定!
dgvc.DisplayMember =姓名;
dgvc.ValueMember =价值;
这个。 dataGridView1.Columns.Add(dgvc);
DataTable dt = new DataTable();
dt.Columns.Add(column1 ,typeof(ComStationType));
DataRow dr = dt.NewRow();
dr [0] = ComStationType.ESPSYS;
dt .Rows.Add(博士);
this.dataGridView1.DataSource = dt;
I want use List<bindentity> bind to DataGridViewComboBoxColumn as a custom datasource.but always occur a dataerror when ui show.i get error message ,it''s about cell value illegal .
what should i do ?
code list below:
enum ComStationType { PCPSYS,ESPSYS...}
class BindEntity
{
public string Name{get}
public object Value{get}
}
DataGridViewComboBoxColumn dgvc = new DataGridViewComboBoxColumn();
dgvc.DisplayStyle = DataGridViewComboBoxDisplayStyle.Nothing;
dgvc.DataPropertyName = "column1";
dgvc.DataSource = GetComStationTypeInfo();//GetComStationTypeInfo() return a List<bindentity> for bind!
dgvc.DisplayMember = "Name";
dgvc.ValueMember = "Value";
this.dataGridView1.Columns.Add(dgvc);
DataTable dt = new DataTable();
dt.Columns.Add("column1", typeof(ComStationType));
DataRow dr = dt.NewRow();
dr[0] = ComStationType.ESPSYS;
dt.Rows.Add(dr);
this.dataGridView1.DataSource = dt;
推荐答案
这篇关于DataGridViewComboBoxColumn绑定数据源发生数据错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!