Vb6 在列表框中获取所选项目

Vb6 在列表框中获取所选项目,vb6,Vb6,我是VB6新手。我需要在列表框中获取所选项目 当我按下Modify按钮时,将其内容设置为文本框的文本 Private Sub Modify_Click() List2.List(0) = Text3.Text End Sub 我需要更改列表框中所选项目的索引0 在VB.Net中,我使用了以下语句,但在VB6中,我不知道如何执行 val=ListBox2.SelectedItem.Value ListIndex返回所选项目的从零开始的索引,如果未选择任何项目,则返回-1。将其与Lis

我是VB6新手。我需要在列表框中获取所选项目 当我按下
Modify
按钮时,将其内容设置为文本框的文本

Private Sub Modify_Click()
    List2.List(0) = Text3.Text
End Sub
我需要更改列表框中所选项目的索引0

在VB.Net中,我使用了以下语句,但在VB6中,我不知道如何执行

val=ListBox2.SelectedItem.Value 

ListIndex
返回所选项目的从零开始的索引,如果未选择任何项目,则返回
-1
。将其与
List()
集合结合使用以检索所选项目

例如:

If List2.ListIndex < 0 Then
    Debug.Print "No item selected."
Else
    Debug.Print "Selected text = " & List2.List(List2.ListIndex)
End If
如果您的
列表框
允许多个选择,则需要在项目之间循环,并使用
Selected()
函数确定所选项目:

For i = 0 To List2.ListCount - 1
    If List2.Selected(i) Then Debug.Print List2.List(i)
Next
因此,要回答您的问题,将所选项目的文本更改为文本框的文本,请使用以下命令:

If List2.ListIndex >= 0 Then
    List2.List(List2.ListIndex) = Text3.Text
End If
If List2.ListIndex >= 0 Then
    List2.List(List2.ListIndex) = Text3.Text
End If