2个组合框和二维阵列

时间:2012-05-10 22:16:22

标签: vb.net arrays combobox

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

在这里的人们的帮助下,我已经能够编辑我的数组,但我的.AddRange()函数出现了问题。当选择类别时,我必须在列表(每个类别)的括号中放入什么才能显示在 2nd 组合框中?

我试过了:

  • .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()
  4. 我在下面附上了我的代码:

    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
    

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

1 个答案:

答案 0 :(得分:0)

在我看来你的问题不是很清楚......顺便说一句,也许我可以通过告诉你,如果我在你身边,我该怎么办。 我将以这种方式声明一个二维数组....例如。索引0的滑稽电影和索引1的kolossal ......

 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) )

希望它有所帮助......