0

我一直在做一个 VB 项目,我使用第一个下拉列表选择电影类别,然后在第二个下拉菜单中,将显示该类别的电影。电影按类别存储在二维数组中。

在人们的帮助下,我已经能够编辑我的数组,但是我的 .AddRange() 函数出现了问题。在选择类别时,我将在列表中放入那些括号(对于每个类别)出现在我的第二组合框中的括号?

我试过:

  • .AddRange (movie_list_combobox)
  • .AddRange (movie_category_combobox)
  • .AddRange (Array(movie_list_combobox))
  • .AddRange (Array(movie_category_combobox))

没有任何效果。

更改的项目:

  1. 更新数组
  2. 我没有使用 if/else 语句,而是使用 for/next(也不再使用 Select Case)
  3. 添加了 addRange()

我在下面附上了我的代码:

Public Class Video_Form

Private Sub count_textbox_TextChanged(ByVal sender As Object, ByVal e As EventArgs) Handles count_textbox.TextChanged

End Sub

Private Sub Count_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Count.Click

  count_textbox.Text = Me.movie_list_combobox.Items.Count

End Sub

Private Sub movie_categories_combobox_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles movie_categories_combobox.SelectedIndexChanged

End Sub

Private Sub movie_list_combobox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movie_list_combobox.SelectedIndexChanged

  Dim Movies(,) As String = {{"Meet", "Oxford", "Sterilite"}, {"Sunflower", "Seeds", ""}, {"Black Box", "", ""}, {"Dancing ", "", ""}, {"Dictionary", "", ""}, {"Glue", "Flight", ""}}

  Dim row As Integer
  Dim column As Integer

  For movie_categories_combobox.SelectedIndex = 0 Then
    row = 0 To 2
    column = 0 To 0
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  For movie_categories_combobox.SelectedIndex = 1 Then
    row = 0 To 1
    column = 1 To 1
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  For movie_categories_combobox.SelectedIndex = 2 Then
    row = 0 To 0
    column = 2 To 2
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  For movie_categories_combobox.SelectedIndex = 3 Then
    row = 0 To 0
    column = 3 To 3
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  For movie_categories_combobox.SelectedIndex = 4 Then
    row = 0 To 0
    column = 4 To 4
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  For movie_categories_combobox.SelectedIndex = 5 Then
    row = 0 To 1
    column = 5 To 5
    movie_list_combobox.Items.Clear()
    movie_list_combobox.Items.AddRange()
  Next

  '//End If
  '//End Select

End Sub

请让我知道我的代码的哪些部分是错误的。

4

1 回答 1

0

在我看来,你的问题不是很清楚......顺便说一句,也许我可以告诉你如果我在你身边我会做什么来帮助你。我将以这种方式声明一个二维数组....例如。有趣的电影在索引 0 和 kolossal 在索引 1....

 Dim array as new string(1,2) ={{"Scary movie", "Ace ventura", "American pie"},   {"Titanic", "avatar", "quo vadis"}}

然后,填充电影类别组合框:

 movie_category_combobox.items.addRange(new string(){"Funny movies", "Kolossal"})

最后,当movie_category_combobox.SelectedIndexChanged 抛出时,您只需要:

 'clear the movie combobox
 movie_list_combobox.items.clear() 

 'fill the movie combobox with the index at the selected position 
 movie_list.combobox.items.addrange(array(movie_category_combobox.selectedIndex) )

希望能帮助到你....

于 2012-05-10T22:39:14.213 回答