列表框中的多个变量

时间:2013-04-23 01:03:57

标签: vb.net visual-studio-2010

好的,所以我在组合框中的选择会在我的列表框中生成不同的列表。我现在要做的是让我在列表框中的选择给我一个变量,这样我就可以使用变量来计算其他东西。(如果我可以如此,如果SeleceIndex = 0那么)我尝试了各种各样的事情避免编写更多私人潜艇并运行它们。

我正在使用VB.net 2010,并且由于一些奇怪的原因,SelectedItem没有给我一个数字。我是否应该使用不同的短语来查找用户选择的列表框中的哪个变量,或者我将不得不将其填充并创建私有潜艇? (即它看起来像这样,但这只是一种变化)。

intticket = cbx1.SelectedIndex
inttickets = lstbx1.SelectedItem 
If intticket = 0 Then
    SeasonSeats()
ElseIf intticket = 1 Then   
    SingleGameSeats() 
End If  
If (intticket = 0) AndAlso (inttickets = 0) Then   
    intseatgame = intseaboxseats      
ElseIf (intticket = 0) AndAlso (inttickets = 1) Then    
    intseatgame = intsealowerdeck     
End If 

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找ListBox.SelectedIndex Property - 这将返回所选项目的从0开始的索引。

你也可以在第一个内部移动第二个If块(这更像是一个风格上的变化):

intticket = cbx1.SelectedIndex
inttickets = lstbx1.SelectedIndex

If intticket = 0 Then
    SeasonSeats()
    if (inttickets = 0) Then
        intseatgame = intseaboxseats
    ElseIf (inttickets = 1) Then
        intseatgame = intsealowerdeck
    End If
ElseIf intticket = 1 Then   
    SingleGameSeats() 
End If  
相关问题