ListView数据填充如下:
//----------------------------------------------------------
// CREATE TABLE
//----------------------------------------------------------
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
DataTable dt =
new DataTable();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dt.Columns.Add(
"A", System.Type.GetType(
"System.String"));
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dt.Columns.Add(
"B", System.Type.GetType(
"System.String"));
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dt.Columns.Add(
"C", System.Type.GetType(
"System.String"));
//----------------------------------------------------------
// SET DATA
//----------------------------------------------------------
for (
int i = 0; i < 100; i++)
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
{
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
DataRow dr = dt.NewRow();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dr[
"A"] =
"A" + i.ToString();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dr[
"B"] =
"B" + i.ToString();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dr[
"C"] =
"C" + i.ToString();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
dt.Rows.Add(dr);
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
}
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.Items.Clear();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.Columns.Clear();
this.listView1.Columns.Add(
"A", 80, HorizontalAlignment.Center);
this.listView1.Columns.Add(
"B", 80, HorizontalAlignment.Center);
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.View = View.Details;
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.GridLines =
true;
string[] str =
new
string[2];
foreach (DataRow row
in dt.Rows)
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
{
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
str[0] = row[
"A"].ToString();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
str[1] = row[
"B"].ToString();
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
ListViewItem item =
new ListViewItem(str, 0);
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.Items.Add(item);
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
}
行单击事件如下:
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.FullRowSelect =
true;
![InBlock.gif](https://s1.51cto.com/images/editer/InBlock.gif)
listView1.GridLines =
true;
转载于:https://blog.51cto.com/jammeswang/291692