如何在 VB6 的列表视图中添加多行项目和子项目?
how to add multiline item and subitem in listview in VB6?
我在文本框中有这样的数据:
我想在列表视图中将该数据的 3 种类型拆分为 3 个列。我知道如何使用这种类型的代码按字符拆分数据:
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set List = ListView1.ListItems.Add(, , a)
ListView1.ListItems.Add.SubItems(1) = b
ListView1.ListItems.Add.SubItems(2) = c
End If
Next i
End Sub
但是结果是这样的:
它不符合这条线。
我的代码怎么了?这是错的吗?
请帮助我,谢谢
我建议您尝试这样的操作,您实际上可以使用 for i .. 循环遍历值数组,但您明白了要点!
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
Dim oItem As ListItem
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set oItem = ListView1.ListItems.Add(, , sValues(0))
Call oItem.ListSubItems.Add(, , sValues(1))
Call oItem.ListSubItems.Add(, , sValues(2))
End If
Next i
End Sub
我在文本框中有这样的数据:
我想在列表视图中将该数据的 3 种类型拆分为 3 个列。我知道如何使用这种类型的代码按字符拆分数据:
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set List = ListView1.ListItems.Add(, , a)
ListView1.ListItems.Add.SubItems(1) = b
ListView1.ListItems.Add.SubItems(2) = c
End If
Next i
End Sub
但是结果是这样的:
它不符合这条线。 我的代码怎么了?这是错的吗? 请帮助我,谢谢
我建议您尝试这样的操作,您实际上可以使用 for i .. 循环遍历值数组,但您明白了要点!
Private Sub Command1_Click()
Dim a As String
Dim b As String
Dim c As String
Dim i As Long
Dim sLines() As String
Dim sValues() As String
Dim oItem As ListItem
sLines() = Split(Text1.Text, vbCrLf)
For i = 0 To UBound(sLines)
If sLines(i) > vbNullString Then ' skip for empty line
sValues() = Split(sLines(i), ".")
a = sValues(0) & vbCrLf
b = sValues(1) & vbCrLf
c = sValues(2) & vbCrLf
Set oItem = ListView1.ListItems.Add(, , sValues(0))
Call oItem.ListSubItems.Add(, , sValues(1))
Call oItem.ListSubItems.Add(, , sValues(2))
End If
Next i
End Sub