Arrays system.string[]/类型为';字符串';无法转换为';字符串()';在列表框vb.net中的选定索引中
这是我在VisualBasic窗口窗体应用程序中创建的一个程序,它使用两个列表框,一个用于数月,另一个用于诞生石。当用户单击诞生石时,LBL说明控件中将显示相应的月份,或者当用户单击_strmonth列表框中的月份时,LBL说明中将显示相应的诞生石。程序正在运行,但我不小心删除了它,现在我不记得确切的代码了。我已经花了一个星期的时间来重新制作它,但是没有效果。我已经研究了SelectedIndex属性,但到目前为止我所看到的一切都是关于SelectedIndex属性是整数,而我的是字符串。所以我来论坛寻求帮助。代码很简单。我添加了一个MsgBox(_intFill),其中显示了所有的诞生石。我快到了,但还没有雪茄Arrays system.string[]/类型为';字符串';无法转换为';字符串()';在列表框vb.net中的选定索引中,arrays,vb.net,listbox,selectedindexchanged,Arrays,Vb.net,Listbox,Selectedindexchanged,这是我在VisualBasic窗口窗体应用程序中创建的一个程序,它使用两个列表框,一个用于数月,另一个用于诞生石。当用户单击诞生石时,LBL说明控件中将显示相应的月份,或者当用户单击_strmonth列表框中的月份时,LBL说明中将显示相应的诞生石。程序正在运行,但我不小心删除了它,现在我不记得确切的代码了。我已经花了一个星期的时间来重新制作它,但是没有效果。我已经研究了SelectedIndex属性,但到目前为止我所看到的一切都是关于SelectedIndex属性是整数,而我的是字符串。所以我
Option Strict On
Public Class frmBirthstones
'Declare class variables
Private _strStones(11) As String
Private _strMonths(11) As String
Public Shared _intFill As String
Public Shared _selectedIndex As String
Private Sub frmBirthstones_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Array items for Brith Stones
_strStones(0) = "Garnet"
_strStones(1) = "Amethyst"
_strStones(2) = "Aquamarine"
_strStones(3) = "Diamond"
_strStones(4) = "Emerald"
_strStones(5) = "Pearl"
_strStones(6) = "Ruby"
_strStones(7) = "Peridot"
_strStones(8) = "Sapphire"
_strStones(9) = "Opal"
_strStones(10) = "Topaz"
_strStones(11) = "Turquoise"
'Array items for Months
_strMonths(0) = "January"
_strMonths(1) = "February"
_strMonths(2) = "March"
_strMonths(3) = "April"
_strMonths(4) = "May"
_strMonths(5) = "June"
_strMonths(6) = "July"
_strMonths(7) = "August"
_strMonths(8) = "September"
_strMonths(9) = "October"
_strMonths(10) = "November"
_strMonths(11) = "December"
'Makes label Description visible
lblDescription.Visible = True
For Each _intFill In _strStones
'fills listbox with Birthstones
lstStones.Items.Add(_intFill)
MsgBox(_intFill)
Next
For Each _intFill In _strMonths
'fills listbox with Months
lstMonths.Items.Add(_intFill)
Next
End Sub
Private Sub lstStones_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstStones.SelectedIndexChanged
'When user click or selects a Birthstone in this listbox a corresponding Month for the Birthstone is selected
'_strStones = _intFill
'Doesn't work
lblDescription.Text = _strStones.ToString() & "is the Birthstone for the month of " & _strMonths.ToString()
End Sub
Private Sub lstMonths_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lstMonths.SelectedIndexChanged
'When user click or selects a Month in this listbox a corresponding Birthstone for that Month is selected
'_strMonths =
lblDescription.Text = _strMonths.ToString() & "is the Month for the Birthstone " & _strStones.ToString()
End Sub
End Class
可能这就是您想要做的。不,SelectedIndex属性肯定是一个整数。您没有使用它,使用数组的ToString()方法毫无意义。您需要strstones(lstStones.SelectedIndex).ToString(),简单。
Option Strict On
Public Class frmBirthstones
Private _strStones(11) As String
Private _strMonths(11) As String
Private Sub frmBirthstones_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
'Array items for Brith Stones
_strStones(0) = "Garnet"
_strStones(1) = "Amethyst"
_strStones(2) = "Aquamarine"
_strStones(3) = "Diamond"
_strStones(4) = "Emerald"
_strStones(5) = "Pearl"
_strStones(6) = "Ruby"
_strStones(7) = "Peridot"
_strStones(8) = "Sapphire"
_strStones(9) = "Opal"
_strStones(10) = "Topaz"
_strStones(11) = "Turquoise"
'Array items for Months
_strMonths(0) = "January"
_strMonths(1) = "February"
_strMonths(2) = "March"
_strMonths(3) = "April"
_strMonths(4) = "May"
_strMonths(5) = "June"
_strMonths(6) = "July"
_strMonths(7) = "August"
_strMonths(8) = "September"
_strMonths(9) = "October"
_strMonths(10) = "November"
_strMonths(11) = "December"
'Makes label Description visible
lblDescription.Visible = True
'fills listbox with Birthstones
lstStones.Items.AddRange(_strStones)
'fills listbox with Months
lstMonths.Items.AddRange(_strMonths)
End Sub
Private Sub lstStones_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lstStones.SelectedIndexChanged
lblDescription.Text = _strStones(lstStones.SelectedIndex).ToString() & " is the Birthstone for the month of " & _strMonths(lstStones.SelectedIndex).ToString()
End Sub
Private Sub lstMonths_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles lstMonths.SelectedIndexChanged
lblDescription.Text = _strMonths(lstMonths.SelectedIndex).ToString() & " is the Month for the Birthstone " & _strStones(lstMonths.SelectedIndex).ToString()
End Sub
End Class