|
//定义结构体
class Target
{
private int _num; //编号
private string _rect; //方向
private string _ring; //环数
public Target(int Num, string Rect, string Ring)
{
this._num = Num;
this._rect = Rect;
this._ring = Ring;
}
//值
public string Rect
{
get { return _rect; }
}
//名称
public string Ring
{
get { return _ring; }
}
//编号
public int Num
{
get { return _num; }
}
}
List<Target> Targets = new List<Target>();
//向Targets中添加数据
、、、、未写出
//listview绑定的模板对应的三个Label的DataMember和DisplayMember对应的三个label分别是"NUM","DIREC", "RING"
DataTable table = new DataTable();
table.Columns.Add("NUM", typeof(System.Int32));
table.Columns.Add("DIREC", typeof(System.String));
table.Columns.Add("RING", typeof(System.String));
//通过输出的messagebox显示来看Targets中是有数据的,但列表却未能显示
listView1.DataSource = Targets;
listView1.DataBind();
用下面方式显示正常
DataTable table = new DataTable(); table.Columns.Add("DIREC", typeof(System.String)); table.Columns.Add("RING", typeof(System.String));
table.Rows.Add("餐费", "中餐+晚餐"); table.Rows.Add("交通费", "的士+火车票"); listView1.Rows.Clear(); //清除数据 if (table.Rows.Count>0) //绑定数据源 { listView1.DataSource = table; listView1.DataBind(); }
|
|