I'll try to explain what I want to do. I'm starting to learn about arrays and I'm trying (and failing all day) to be able to create a list in a dropdown menu of filmtypes: "Comedy" "Thriller etc.
When I select one of them "Comedy" for example I want that to appear in the list below.
I've attached the code I've written so far:
hope someone can help.
thanks,
Chris Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load With ComboBoxSelectType.Items
.Add("Comedy")
.Add("Thriller")
.Add("Horror")
.Add("Animation")
End With End Sub Private Sub ComboBoxSelectType_SelectedValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBoxSelectType.SelectedValueChanged Dim Comedy(5) As StringComedy(0) = "The Best of Jasper Carrot"
Comedy(1) = "Goldmember"
Comedy(2) = "The Man Who Sued God"
Comedy(3) = "The Life of Brian"
Comedy(4) = "24 Carrot Gold"
Comedy(5) = "Peter Kay"
If ComboBoxSelectType.SelectedItem Is Comedy ThenListBoxAvailableDVDs. = Comedy
End If
Arrays
DorD
You could use the text to determine the type or use a value. Using the text would cause the application to break if you chnaged the text or tried using in a different language however a value would be less susceptible.
This defines an item pair with a value and a name
Public
Class ClsItemPair Dim sParameterName As String Dim SValue As String Public Property ParameterName() As String Get Return sParameterName End Get Set(ByVal value As String)sParameterName = value
End Set End Property Public Property Value() As String Get Return SValue End Get Set(ByVal value As String)SValue = value
End Set End Property Public Sub New(ByVal ParameterName As String, ByVal Value As String) Me.ParameterName = ParameterName Me.Value = Value End Sub Public Overrides Function ToString() As String Return sParameterName.ToString() End FunctionEnd
ClassIf you use this to add items to the listbox
Dim Obj as new ClsItemPair ("Comedy",1)
ListBox1.add (Obj)
When you want to determine the selected Item
Use
Dim Obj as ClsItempair
ListBox1.selectedItem
IF Obj1.Value = 1 then
End if
Of course instead of using hardcoded values such as 1 you could enumerate these.
Public Enum FileGenre
Comedy = 1
Action
Thriller
End Enum
and then use something like FileGenre.Comedy instead of 1
If you pick the the items up from a database then you can populate the listbox by setting the datasource, valuemember and displaymember properties
Just some ideas.
beng2k
If ComboBoxSelectType.SelectedItem Is Comedy Then
This makes no sense. I'm surprised it compiles. The 'is' keyword is used to see if an object is of a specific type. For this to compile, Comedy has to be the name of a class.
What you want to do, I believe, is
If ComboBoxSelectType.SelectedText = "Comedy" Then
I may be wrong about there being a 'SelectedText' property, but it's something like that.
You would use 'is' to, for example, check which derived class an instance of a base class is, or if a class impliments a specific interface. For example, I have collections of classes which I use via a base class instance, and only some need to call Dispose. so I check first if my instance can be disposed like this:
if (myInstance is IDisposable ) ((IDisposable)myInstance).Dispose();