在select语句中引用所选索引

时间:2014-08-01 14:46:13

标签: vb.net

而不是使用Text的{​​{1}}属性我试图使用ListBox属性,这样当我在一个列表框中选择某个名称时,项目会被添加到另一个列表框中列表框。这是我目前正在使用的代码。

SelectedIndex

如果我使用的是Ward = ListBox1.SelectedIndex ListBox2.Items.Clear() Select Case Ward Case ListBox2.Items.Add("Fred Jones") ListBox2.Items.Add("John Green") ListBox2.Items.Add("Imran Shah") 属性,那么情况就是"弗莱明",但如果我使用Text属性,该怎么办?

1 个答案:

答案 0 :(得分:0)

好吧,因为SelectedIndex是一个整数,你的情况就是这样:

Ward = ListBox1.SelectedIndex
ListBox2.Items.Clear()
Select Case Ward
    Case 1
        ListBox2.Items.Add("Fred Jones")
        ListBox2.Items.Add("John Green")
        ListBox2.Items.Add("Imran Shah")

我不知道这是否是最好的方法。如果您的索引在以后更改,您的案例将被抛弃。你可能想坚持使用文字。