vb中如何在listview中添加数据?
Dim xx As ListItem
Set xx = ListView1.ListItems.Add(, , "111")
xx = ListView1.ListItems.Add(, , "222")
xx = ListView1.ListItems.Add(, , "333")
xx = ListView1.ListItems.Add(, , "444")
End Sub
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列", 1000
ListView1.ColumnHeaders.Add , , "第2列", 1000
ListView1.ColumnHeaders.Add , , "第3列", 1000
End Sub
代码如上,最后第一列第一行也就变成444了,下边是222,333,444.
请问,第一行为什么不是111
还有我在Private Sub Command2_Click()中写入什么代码会在第二列第一行输入数据? 展开
用代码进行说一下:
Private Sub Command1_Click()
Dim xx As ListItem
If Text1.Text <> "" And Text2.Text <> "" And Text3.Text <> "" Then
Set xx = ListView1.ListItems.Add(, , Text1.Text)
xx.SubItems(1) = Text2.Text
xx.SubItems(2) = Text3.Text
Set xx = Nothing
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub
Private Sub Form_Load()
ListView1.View = lvwReport
ListView1.ColumnHeaders.Add , , "第1列", 1000
ListView1.ColumnHeaders.Add , , "第2列", 1000
ListView1.ColumnHeaders.Add , , "第3列", 1000
End Sub
ListView1.ListItems.Add , , "2"
ListView1.ListItems.Add , , "3"
ListView1.ListItems.Add , , "4"
在Command1里改成这样
Private Sub Command2_Click()
Dim X As ListItem
Set X = ListView1.ListItems(1) '第一行
'X.SubItems(1) = "aaaa" '第二列
X.SubItems(2) = "bb" '第三列
End Sub
Sub
Command1_Click()
Dim
xx
As
ListItem
Set
xx
=
ListView1.ListItems.Add(,
,
"1111")
xx.SubItems(1)
=
"2222"
xx.SubItems(2)
=
"3333"
End
Sub
Private
Sub
Form_Load()
ListView1.View
=
lvwReport
ListView1.ColumnHeaders.Add
,
,
"第1列",
1000
ListView1.ColumnHeaders.Add
,
,
"第2列",
1000
ListView1.ColumnHeaders.Add
,
,
"第3列",
1000
End
Sub