Smobiler上海石磨_.NET移动开发平台
标题:
listview绑定数据不显示
[打印本页]
作者:
chengxianchao
时间:
2021-2-2 23:55
标题:
listview绑定数据不显示
//定义结构体
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(); }
作者:
Lula.Jin
时间:
2021-2-3 09:47
[attach]2131[/attach]结构体的属性请与listview模板类中的绑定值一致,listview的绑定值是大写的,结构体相应属性也需要是大写的
欢迎光临 Smobiler上海石磨_.NET移动开发平台 (https://www.smobiler.cn/)
Powered by Discuz! X3.2