2011-11-19 43 views
0

我想在我的列表框中搜索一小段文本,如果它在列表框中,我想选择它,然后将其转换为字符串。从列表框中选择行,然后转换为字符串

我该怎么做?

因为我找不到在特定行上选择某个东西的好命令!

感谢

+2

您能显示您尝试过的代码并解释它失败的位置吗? –

回答

1

要选择列表框项,设定ListBox的SelectedIndex财产。因此,例如:

Dim stringToFind As String = "someString" 

For i As Integer = 0 To Me.MyListBox.Items.Count - 1 
    Dim itemAsString As String = Me.MyListBox.Items(i).ToString() 
    If itemAsString.Contains(stringToFind) Then 
     Me.MyLabel.Text = itemAsString 
     Me.MyListBox.SelectedIndex = i 
     Exit For 'If you're using a MultiSelect ListBox, you can add to Me.MyListBox.SelectedIndices and remove this line. 
    End If 
Next 
+0

它完美地工作,但是如何将其复制到另一个标签? – user1054822

+0

@ user1054822:只需将'itemAsString'分配给您的标签的'Text'属性。我已经编辑了我的答案来包含这一点。 – Ryan

相关问题