ListView的常用方法
2007-02-25 22:10 ruinet 阅读(792) 评论(0) 编辑 收藏 举报下面是ListView的常用方法
1 Private Sub LoadListView()
2 '增加列头
3 With ListView1
4 .Columns.Clear()
5 .Columns.Add("From", 80, HorizontalAlignment.Left)
6 .Columns.Add("说明", 90, HorizontalAlignment.Left)
7 End With
8
9 '增加项
10 With ListView1
11 .Items.Clear()
12 .Items.Add("From1", 0)
13 .Items.Add("From2", "From2", 1)
14 .Items.Add("From3", 0)
15 .Items.Add("From4", "From4", 0)
16 .Items.Add("From5", "From5", 0)
17 End With
18
19 '增加分组
20
21 With ListView1
22 .Groups.Clear()
23 .Groups.Add("groupKey", "分组1--2007/2/23")
24 .Groups.Add("Group2", "分组2")
25 .Groups.Add("Group3", "分组3")
26 End With
27
28
29 '增加项
30 Dim Item As ListViewItem = ListView1.Items.Add("ItemText")
31 Item.SubItems.Add("ItemText--SubItem")
32 Item.Group = ListView1.Groups(2)
33
34
35
36 '查找项
37 Dim foundItem As ListViewItem = ListView1.FindItemWithText("From1", True, 0, True)
38
39 '设置分组
40 If Not (foundItem Is Nothing) Then
41 foundItem.Group = ListView1.Groups("groupKey")
42 End If
43
44 ListView1.Items("From2").Group = ListView1.Groups("Group2")
45 ListView1.Items("From4").Group = ListView1.Groups("Group2")
46 ListView1.Items("From5").Group = ListView1.Groups("Group3")
47
48 End Sub
界面显示如图:
2 '增加列头
3 With ListView1
4 .Columns.Clear()
5 .Columns.Add("From", 80, HorizontalAlignment.Left)
6 .Columns.Add("说明", 90, HorizontalAlignment.Left)
7 End With
8
9 '增加项
10 With ListView1
11 .Items.Clear()
12 .Items.Add("From1", 0)
13 .Items.Add("From2", "From2", 1)
14 .Items.Add("From3", 0)
15 .Items.Add("From4", "From4", 0)
16 .Items.Add("From5", "From5", 0)
17 End With
18
19 '增加分组
20
21 With ListView1
22 .Groups.Clear()
23 .Groups.Add("groupKey", "分组1--2007/2/23")
24 .Groups.Add("Group2", "分组2")
25 .Groups.Add("Group3", "分组3")
26 End With
27
28
29 '增加项
30 Dim Item As ListViewItem = ListView1.Items.Add("ItemText")
31 Item.SubItems.Add("ItemText--SubItem")
32 Item.Group = ListView1.Groups(2)
33
34
35
36 '查找项
37 Dim foundItem As ListViewItem = ListView1.FindItemWithText("From1", True, 0, True)
38
39 '设置分组
40 If Not (foundItem Is Nothing) Then
41 foundItem.Group = ListView1.Groups("groupKey")
42 End If
43
44 ListView1.Items("From2").Group = ListView1.Groups("Group2")
45 ListView1.Items("From4").Group = ListView1.Groups("Group2")
46 ListView1.Items("From5").Group = ListView1.Groups("Group3")
47
48 End Sub