Listview的简单使用心得:
标题的建立:
this.listView1.Columns.Add("变量名称", 120, HorizontalAlignment.Left); //一步添加
this.listView1.Columns.Add("变量地址", 120, HorizontalAlignment.Left); //一步添加
this.listView1.Columns.Add("数据类型", 120, HorizontalAlignment.Left); //一步添加
this.listView1.Columns.Add("变量值", 120, HorizontalAlignment.Left); //一步添加
数据的填充:
if (plc_var_names.Rows.Count > 0)
{
for (int i = 0; i < plc_var_names.Rows.Count; i++)
{
ListViewItem lvi = new ListViewItem();
lvi.Text = plc_var_names.Rows[i]["name"].ToString();
lvi.SubItems.Add(plc_var_names.Rows[i]["plc_addr"].ToString());
lvi.SubItems.Add(plc_var_names.Rows[i]["variable_type"].ToString());
lvi.SubItems.Add(plc_var_names.Rows[i]["value"].ToString());
}
this.listView1.Items.Add(lvi);
}