1

私は学生です、私に耐えてください...以下は私のコードです:

Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, 
 ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged

  'declare variables
  Dim intSelectedYear As Integer
  Dim intNumhUUR As Integer

  'select year from combobox
  intSelectedYear = cboYear.SelectedIndex

  ' get number of hurricanes for selected year from number 
  ' of hurricanes array 
  intNumhUUR = _intNumberOfHurricanes(intSelectedYear)

  'and display in label
  lblNumberOfHurricanes.Visible = True
  lblNumberOfHurricanes.Text = "The number of Hurricanes " &
    "in the year " & intSelectedYear.ToString & "  is " & 
    intNumhUUR.ToString()
End Sub
4

2 に答える 2

2

SelectedItemその場所で現在選択されているアイテムを取得するには、コンボボックスのプロパティを使用する必要がありSelectedIndexます。すなわち:

Private Sub cboYear_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboYear.SelectedIndexChanged
  'declare variables
  Dim intSelectedIndex As Integer
  Dim intNumhUUR As Integer
  Dim strSelectedYear As String

  'select year from combobox
  intSelectedIndex = cboYear.SelectedIndex
  strSelectedYear = cboYear.SelectedItem.ToString()
  ' get number of hurricanes for selected year from number 
  ' of hurricanes array 
  intNumhUUR = _intNumberOfHurricanes(intSelectedIndex)

  'and display in label
  lblNumberOfHurricanes.Visible = True
  lblNumberOfHurricanes.Text = string.Format("The number of Hurricanes in the year {0} is {1}", strSelectedYEar, intNumhUUR)
End Sub
于 2012-04-13T00:44:20.663 に答える
0

cboYear はドロップダウン リストですか。 cboYear.SelectedValue で文字列が得られると思います。

于 2012-04-13T00:46:10.040 に答える