Question List box and arrays

kjhip1

New member
Joined
Aug 2, 2009
Messages
1
Programming Experience
Beginner
I have two sets of data which need to be put into an array. One with aisle number and the corresponding movie genre. My job is to create a list box for the genres (comedy, drama, action, Sci-Fi, Horror, and New Releases) and use a textbox which displays the corresponding aisle number when the genre is selected and the search button is pressed. My biggest problem is that I cannot get the text box to display anything. Thanks in advance. I have pasted what I have so far.

VB.NET:
Public Class Form1
    Structure Group
        Dim genreString As String
        Dim aisleString As String
    End Structure
    Private movieGroup(5) As Group
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        movieGroup(0).genreString = "Comedy"
        movieGroup(1).genreString = "Drama"
        movieGroup(2).genreString = "Action"
        movieGroup(3).genreString = "Sci-Fi"
        movieGroup(4).genreString = "Horror"
        movieGroup(5).genreString = "New Releases"
    End Sub
    Private aisleString(5) As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim aislenumberString As String
        Dim indexInteger As Integer
        Try
            With Me
                indexInteger = .ListBox1.SelectedIndex
                If indexInteger <> -1 Then
                    'find correct aisle
                    aislenumberString = Integer.Parse(.AisleNumber.Text)

                    .ListBox1.SelectedIndex = 5
                    .AisleNumber.Text = "Back Wall"

                Else
                    MessageBox.Show("Must select a movie category.", "Data Missing", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                End If

            End With
        Catch ex As Exception
        End Try

    End Sub
End Class
 
Last edited by a moderator:
How about using collections.generics.dictionary(Of Tkey, TValue)?
This would store a key and a value that are paired together. then store the key in the listbox and with the selectedindexChanged event display the value in the textbox. You could use:
VB.NET:
Dim xList As New Dictionary(Of String, String)
xList.Add([genre], [aisle])
'selectedIndexChaned event...
For Each k As KeyValuePair(Of String, String) In xList
   If k.Key = listbox1.SelectedItem.ToString Then
       textbox1.Text = k.Value
   End If
Next
 
Back
Top