在winform中listView1怎么绑定数据库
推荐于2016-09-25
展开全部
private void FrmXMLShow_Load(object sender, EventArgs e)
{
// listview样式设置
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Scrollable = false;
listView1.MultiSelect = false;
listView1.HeaderStyle = ColumnHeaderStyle.Clickable;
// 表头设置
listView1.Columns.Add("ID", 50, HorizontalAlignment.Center);
listView1.Columns.Add("姓名", 50, HorizontalAlignment.Center);
listView1.Columns.Add("性别", 50, HorizontalAlignment.Center);
listView1.Columns.Add("年龄", 50, HorizontalAlignment.Center);
listView1.Columns.Add("学校", 150, HorizontalAlignment.Center);
listView1.Columns.Add("联系电话", 150, HorizontalAlignment.Center);
foreach (Information i in ixs.ReadAllInformation())
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = i.Id;
item.SubItems.Add(i.Name);
item.SubItems.Add(i.Gender);
item.SubItems.Add(i.Age.ToString());
item.SubItems.Add(i.University);
item.SubItems.Add(i.Phone);
listView1.Items.Add(item);
}
}
{
// listview样式设置
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.View = View.Details;
listView1.Scrollable = false;
listView1.MultiSelect = false;
listView1.HeaderStyle = ColumnHeaderStyle.Clickable;
// 表头设置
listView1.Columns.Add("ID", 50, HorizontalAlignment.Center);
listView1.Columns.Add("姓名", 50, HorizontalAlignment.Center);
listView1.Columns.Add("性别", 50, HorizontalAlignment.Center);
listView1.Columns.Add("年龄", 50, HorizontalAlignment.Center);
listView1.Columns.Add("学校", 150, HorizontalAlignment.Center);
listView1.Columns.Add("联系电话", 150, HorizontalAlignment.Center);
foreach (Information i in ixs.ReadAllInformation())
{
ListViewItem item = new ListViewItem();
item.SubItems.Clear();
item.Text = i.Id;
item.SubItems.Add(i.Name);
item.SubItems.Add(i.Gender);
item.SubItems.Add(i.Age.ToString());
item.SubItems.Add(i.University);
item.SubItems.Add(i.Phone);
listView1.Items.Add(item);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询