【问题标题】:how to add multiline item and subitem in listview in VB6?如何在 VB6 的列表视图中添加多行项目和子项目?
【发布时间】:2017-06-26 07:18:39
【问题描述】:

我在文本框中有这样的数据:

我想在列表视图中将该数据的 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

但是结果是这样的:

它与这条线没有关系。 我的代码会发生什么?这是错的吗? 请帮帮我,谢谢

【问题讨论】:

    标签: listview vb6 add subitem


    【解决方案1】:

    我建议你尝试这样的事情,你实际上可以使用 for i .. 循环遍历 values 数组,但你明白了要点!

    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
    

    【讨论】:

    • diastri,删除所有带有 a、b 和 c 变量的行,不需要填充 ListView。
    • 好点@GiorgioBrausi,它们不是必需的。正如我之前提到的,我还会循环遍历 sValues 来填充 SubItems。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2012-07-12
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多