No no no...
guiComboBox is derived from Textbox. The actual contents of the box are the
textbox, and there are two controls "attached to" it. A button (the
dropdown button), and a listbox (the list of items that drops down).
So the BASE of ComboBox is guiTextBox... to access the button and listbox,
you do guiComboBox.Button and guiComboBox.List... but to access the box
itself, you just use guiComboBox.Text (or whatever other property a
guiTextBox would have)
I also extended the control (the guiTextBox base) to include events that are
raised when the Button or List is clicked.
Private Sub Button_Click(ByVal sender As guiControlBase, ByVal MouseData
As MouseStates, ByVal btn As GUIMouseButtons) Handles Button.Click, Me.Click
List.Visible = Not List.Visible
List.BringToFront()
RaiseEvent ButtonClicked()
End Sub
So you see, that there handles the list being visible or not when the button
is clicked or when the textbox itself is clicked.
When the button is clicked again, of course the list goes invisible...
But when an ITEM in the listbox is selected, the guiListBox object raises
its own event: guiListBox.SelectedItemChanged
guiComboBox handles THAT event internally:
Private Sub ItemSelected(ByVal SelItem As guiControlBase) Handles
List.SelectedItemChanged
List.Visible = False
Focus = True
SelectedItem = SelItem
RaiseEvent SelectedItemChanged(SelectedItem)
End Sub
guiComboBox.SelectedItem is set to the item that guiListBox sent via the
event, and the SelectedItemChanged event is fired off.
You can either handle SelectedItemChanged (which passes in the new item as
an argument of the event), or you can simply look at
guiComboBox.SelectedItem to access the selected item directly.
If you look in the EEGUI Demo, you will see an example of this.
Private Sub ItemSelected(ByVal newitem As guiControlBase) Handles
MyBase.SelectedItemChanged
Text = CType(SelectedItem, guiLabel).Text
End Sub
You have to do a CType (direct casting) to guiLabel in this case, because
the ITEM itself is only the BASE TYPE "guiControlBase", which is the base
type of everything.
That above sub is part of a class that inherits from guiComboBox (see Class
ComboBox in the EEGUI Demo), so the Text property is actually the combo
box's text property that is being changed.
Note that I did NOT include that sub IN the combo box base class itself,
because the item that is selected MAY NOT BE A LABEL!
You can have a combo box that drops down a list of window objects that have
many children, and which all use a TagID for sorting, but a TagString for
the text property you want to use when they're selected from the Combo Box
list.
Let's say in your game you have a combo box that selects which character you
want to use... the selection list could be a sorted list of window objects
200px high, containing detailed information on each character... each ENTRY
in the list is a complex window object containing many children including an
image, labels, etc... but the overall container object for all of these
children is merely that... a container.
When generating the containers, you could set TagID = 1, TagString =
CharacterName
So, you drop down the combo box, and its list box is fricking HUGE, right?
It has 6 different character listing objects, each with all of their
children... you click on one of them, and the listbox says "Hey, selected
item changed!" and passes up the entire character selection container object
as the item that was selected, right?
So then, the combo box itself triggers a "SelectedItemChanged" event of its
own, passing along with it the entire object. YOU would have to handle that
event to do: "Okay, I have a new selected object... I want to set the TEXT
of the combo box itself to the character NAME, which is in the TagString
property of the selected object:
Private Sub ItemSelected(ByVal newitem As guiControlBase) Handles
MyBase.SelectedItemChanged
Text = SelectedItem.TagString
End Sub
Or, you could do more there if you wanted to...
This whole thing was set up to be flexible to account for a lot of different
uses... just remember that with great flexibility comes greater complexity.
:)
Jared Mark
Technical Support and
VB.NET Programmer
If you need Technical Support or Training, click the image below!