C# 将绑定源数据源设置为通用ILST<&燃气轮机;错误
如果我想将BindingSource上的DataSource属性设置为IList,我是否需要按照下面的错误消息所示进行显式转换,或者我是否做错了什么C# 将绑定源数据源设置为通用ILST<&燃气轮机;错误,c#,data-binding,datagridview,ilist,generic-list,C#,Data Binding,Datagridview,Ilist,Generic List,如果我想将BindingSource上的DataSource属性设置为IList,我是否需要按照下面的错误消息所示进行显式转换,或者我是否做错了什么 interface IView { IList<OrderItems> BindingSource { get; set;} } public partial class Form1 : Form, IView { public Form1() {
interface IView
{
IList<OrderItems> BindingSource { get; set;}
}
public partial class Form1 : Form, IView
{
public Form1()
{
InitializeComponent();
}
private BindingSource _bindingSource;
public IList<OrderItems> BindingSource
{
get { return _bindingSource; }
set
{
_bindingSource.DataSource = value;
dataGridView1.DataSource = _bindingSource;
}
}
}
interface-IView
{
IList BindingSource{get;set;}
}
公共部分类表单1:表单,IView
{
公共表格1()
{
初始化组件();
}
私有BindingSource\u BindingSource;
公共IList绑定源
{
获取{return\u bindingSource;}
设置
{
_bindingSource.DataSource=值;
dataGridView1.DataSource=\u bindingSource;
}
}
}
OrderItems.cs
using System;
using System.Collections.Generic;
namespace Ordering.Data
{
/// <summary>
/// Order object for NHibernate mapped table 'Order'.
/// </summary>
[Serializable]
public class OrderItems
{
#region Member Variables
protected int _id;
protected Customers _customers;
protected string _ordername;
protected DateTime _orderdate;
protected DateTime? _shipdate;
protected string _shipvia;
protected string _shipname;
protected string _shipaddress;
protected string _shipcity;
protected string _shipregion;
protected string _shippostalcode;
protected string _shipcountry;
protected string _status;
protected DateTime? _lastupdate;
protected IList<Products> _products;
#endregion
#region Constructors
public OrderItems() {}
public OrderItems(Customers customers, string ordername, DateTime orderdate, DateTime? shipdate, string shipvia, string shipname, string shipaddress, string shipcity, string shipregion, string shippostalcode, string shipcountry, string status, DateTime? lastupdate)
{
this._customers= customers;
this._ordername= ordername;
this._orderdate= orderdate;
this._shipdate= shipdate;
this._shipvia= shipvia;
this._shipname= shipname;
this._shipaddress= shipaddress;
this._shipcity= shipcity;
this._shipregion= shipregion;
this._shippostalcode= shippostalcode;
this._shipcountry= shipcountry;
this._status= status;
this._lastupdate= lastupdate;
}
public OrderItems(Customers customers, string ordername, DateTime orderdate)
{
this._customers= customers;
this._ordername= ordername;
this._orderdate= orderdate;
}
#endregion
#region Public Properties
public virtual int Id
{
get { return _id; }
set { _id = value; }
}
public virtual Customers Customers
{
get { return _customers; }
set {_customers= value; }
}
public virtual string OrderName
{
get { return _ordername; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "OrderName cannot contain more than 255 characters");
if (value != this._ordername){_ordername= value;}}
}
public virtual DateTime OrderDate
{
get { return _orderdate; }
set {if (value != this._orderdate){_orderdate= value;}}
}
public virtual DateTime? ShipDate
{
get { return _shipdate; }
set {if (value != this._shipdate){_shipdate= value;}}
}
public virtual string ShipVia
{
get { return _shipvia; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipVia cannot contain more than 255 characters");
if (value != this._shipvia){_shipvia= value;}}
}
public virtual string ShipName
{
get { return _shipname; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipName cannot contain more than 255 characters");
if (value != this._shipname){_shipname= value;}}
}
public virtual string ShipAddress
{
get { return _shipaddress; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipAddress cannot contain more than 255 characters");
if (value != this._shipaddress){_shipaddress= value;}}
}
public virtual string ShipCity
{
get { return _shipcity; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipCity cannot contain more than 255 characters");
if (value != this._shipcity){_shipcity= value;}}
}
public virtual string ShipRegion
{
get { return _shipregion; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipRegion cannot contain more than 255 characters");
if (value != this._shipregion){_shipregion= value;}}
}
public virtual string ShipPostalcode
{
get { return _shippostalcode; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipPostalcode cannot contain more than 255 characters");
if (value != this._shippostalcode){_shippostalcode= value;}}
}
public virtual string ShipCountry
{
get { return _shipcountry; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "ShipCountry cannot contain more than 255 characters");
if (value != this._shipcountry){_shipcountry= value;}}
}
public virtual string Status
{
get { return _status; }
set {
if ( value != null && value.Length > 255)
throw new ArgumentOutOfRangeException("value", value.ToString(), "Status cannot contain more than 255 characters");
if (value != this._status){_status= value;}}
}
public virtual DateTime? LastUpdate
{
get { return _lastupdate; }
set {if (value != this._lastupdate){_lastupdate= value;}}
}
public virtual IList<Products> Products
{
get { return _products; }
set {_products= value; }
}
#endregion
#region Equals And HashCode Overrides
/// <summary>
/// local implementation of Equals based on unique value members
/// </summary>
public override bool Equals( object obj )
{
if( this == obj ) return true;
if( ( obj == null ) || ( obj.GetType() != this.GetType() ) ) return false;
OrderItems castObj = (OrderItems)obj;
return ( castObj != null ) &&
this._id == castObj.Id;
}
/// <summary>
/// local implementation of GetHashCode based on unique value members
/// </summary>
public override int GetHashCode()
{
int hash = 57;
hash = 27 * hash * _id.GetHashCode();
return hash;
}
#endregion
}
}
使用系统;
使用System.Collections.Generic;
名称空间排序.Data
{
///
///NHibernate映射表“Order”的Order对象。
///
[可序列化]
公共类OrderItems
{
#区域成员变量
受保护的int_id;
受保护客户(u客户);;
受保护的字符串\u ordername;
受保护的日期时间_orderdate;
受保护日期时间?\u发货日期;
受保护管柱_shippvia;
受保护字符串\u shipname;
受保护字符串\u shipaddress;
受保护的字符串\u shipcity;
受保护的字符串\u shippregion;
受保护字符串\u shippastalcode;
受保护字符串(u shippcountry);
受保护的字符串\u状态;
受保护的日期时间?\u上次更新;
受保护的IList_产品;
#端区
#区域构造函数
public OrderItems(){}
公共订单项(客户、字符串ordername、DateTime orderdate、DateTime?shipdate、字符串shipvia、字符串shipname、字符串shipaddress、字符串shipcity、字符串shipregion、字符串shippostalcode、字符串shipcountry、字符串状态、日期时间?上次更新)
{
这是。_客户=客户;
这是。_ordername=ordername;
这是。_orderdate=orderdate;
这是.\u shipdate=shipdate;
这个。_shipvia=shipvia;
这个._shipname=shipname;
这._shipaddress=shipaddress;
这个._shipcity=shipcity;
此._shipregion=shipregion;
这。_shippastalcode=shippastalcode;
这个._shipcountry=shipcountry;
此状态=状态;
这是.\u lastupdate=lastupdate;
}
public OrderItems(客户、字符串ordername、日期时间orderdate)
{
这是。_客户=客户;
这是。_ordername=ordername;
这是。_orderdate=orderdate;
}
#端区
#区域公共财产
公共虚拟整数Id
{
获取{return\u id;}
设置{u id=value;}
}
公共虚拟客户
{
获取{return\u customers;}
设置{u customers=value;}
}
公共虚拟字符串OrderName
{
获取{return\u ordername;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“OrderName不能包含超过255个字符”);
如果(value!=this.\u ordername){{u ordername=value;}}
}
公共虚拟日期时间OrderDate
{
获取{return\u orderdate;}
设置{if(value!=this.\u orderdate){{u orderdate=value;}}
}
公共虚拟日期时间?发货日期
{
获取{return\u shipdate;}
设置{if(value!=this.\u shipdate){{u shipdate=value;}}
}
公共虚拟字符串shippia
{
获取{return\u shipvia;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipVia不能包含超过255个字符”);
如果(value!=this.\u shipvia){u shipvia=value;}
}
公共虚拟字符串ShipName
{
获取{return\u shipname;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipName不能包含超过255个字符”);
如果(value!=this.\u shipname){{u shipname=value;}}
}
公共虚拟字符串地址
{
获取{return\u shipaddress;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipAddress不能包含超过255个字符”);
如果(value!=this.\u shipaddress){u shipaddress=value;}
}
公共虚拟城市
{
获取{return\u shipcity;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipCity不能包含超过255个字符”);
如果(value!=this.\u shipcity){u shipcity=value;}
}
公共虚拟字符串区域
{
获取{return\u shipregion;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipRegion不能包含超过255个字符”);
如果(值!=this.\u shipregion){u shipregion=value;}
}
公共虚拟字符串shippastalcode
{
获取{return\u shippastalcode;}
设置{
如果(值!=null&&value.Length>255)
抛出新ArgumentOutOfRangeException(“value”,value.ToString(),“ShipPostalcode不能包含超过255个字符”);
如果(价值=
return _bindingSource.DataSource as IList<OrderItems>;