首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

C#Winform中为什么设置DataGridViewComboBoxColumn.DisplayMember时会提示出错"未将对象引用设置到对象的实

2012-01-12 
C#,Winform中为什么设置DataGridViewComboBoxColumn.DisplayMember时会提示出错未将对象引用设置到对象的

C#,Winform中为什么设置DataGridViewComboBoxColumn.DisplayMember时会提示出错"未将对象引用设置到对象的实例"
public Entities.TList<Entities.Products> ProductIdList
{
get {return this._ProductIdList;}
set 
{
this._ProductIdList = value;
this.uxProductIdDataGridViewColumn.DataSource = null;
   
  this.uxProductIdDataGridViewColumn.DisplayMember = "ProductName";//这句出错:“未将对象引用设置到对象的实例”,明明:uxProductIdDataGridViewColumn.DisplayMember 值是看的到是为""
  this.uxProductIdDataGridViewColumn.ValueMember = "ProductId";

this.uxProductIdDataGridViewColumn.DataSource = this._ProductIdList;
}
}
//========请高手指点一二!

[解决办法]
你试一试这样写:
public Entities.TList <Entities.Products > ProductIdList
{
get {return this._ProductIdList;}
set 
{
this._ProductIdList = value;
this.uxProductIdDataGridViewColumn.DataSource = this._ProductIdList;

this.uxProductIdDataGridViewColumn.DisplayMember = "ProductName"; 
this.uxProductIdDataGridViewColumn.ValueMember = "ProductId";
}
}
[解决办法]
要先设数据源,再操作显示,this.uxProductIdDataGridViewColumn.DataSource =null 
为空,当然会错了

热点排行