private void btnListView_Click(object sender, EventArgs e)
{
listView2.Groups.Clear();
listView2.Items.Clear();
listView2.View = View.Details;
ColumnHeader columnHeader0 = new ColumnHeader();
columnHeader0.Text = "Title";
columnHeader0.Width = 200;
ColumnHeader columnHeader1 = new ColumnHeader();
columnHeader1.Text = "Author";
columnHeader1.Width = 200;
ColumnHeader columnHeader2 = new ColumnHeader();
columnHeader2.Text = "Year";
columnHeader2.Width = 100;
listView2.Columns.AddRange(new ColumnHeader[] { columnHeader0, columnHeader1, columnHeader2 });
ListViewGroup group1 = new ListViewGroup("001");
ListViewGroup group2 = new ListViewGroup("002");
listView2.Groups.Add(group1);
listView2.Groups.Add(group2);
// Create items and add them to myListView.
ListViewItem item0 = new ListViewItem(new string[]
{"Programming Windows",
"Petzold, Charles",
"1998"}, 0, group1);
ListViewItem item1 = new ListViewItem(new string[]
{"Code: The Hidden Language of Computer Hardware and Software",
"Petzold, Charles",
"2000"}, 0, group1);
ListViewItem item2 = new ListViewItem(new string[]
{"Programming Windows with C#",
"Petzold, Charles",
"2001"}, 0, group1);
ListViewItem item3 = new ListViewItem(new string[]
{"Coding Techniques for Microsoft Visual Basic .NET",
"Connell, John",
"2001"}, 1, group2);
ListViewItem item4 = new ListViewItem(new string[]
{"C# for Java Developers",
"Jones, Allen & Freeman, Adam",
"2002"}, 1, group2);
ListViewItem item5 = new ListViewItem(new string[]
{"Microsoft .NET XML Web Services Step by Step",
"Jones, Allen & Freeman, Adam",
"2002"}, 1, group2);
listView2.Items.AddRange(
new ListViewItem[] { item0, item1, item2, item3, item4, item5 });
}
沒有留言:
張貼留言