listView属性View设置为Details (视图为详细显示);
listView属性GridLins设置为true(显示网格);
SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=123;database=ECMS");
SqlDataAdapter adapter = new SqlDataAdapter("select * from CM_User",con);
DataSet ds = new DataSet();
con.Open();
adapter.Fill(ds,"CM_User");
con.Close();
DataTable dt = new DataTable();
dt = ds.Tables["CM_User"];
for (int n = 0; n < dt.Rows.Count; n++)
{
ListViewItem item = new ListViewItem( dt.Rows[n]["UserID"].ToString());
item.SubItems.Add(dt.Rows[n]["UserName"].ToString());
item.SubItems.Add(dt.Rows[n][2].ToString());
item.SubItems.Add(dt.Rows[n][3].ToString());
item.SubItems.Add(dt.Rows[n][4].ToString());
listView1.Items.Add(item);
}
取值 if (listView1.SelectedItems.Count == 0)
{
return;
}
string cardno=listView1.SelectedItems[0].SubItems[0].Text;