Combo Box

7 views
Skip to first unread message

xavram

unread,
Aug 12, 2009, 4:15:10 PM8/12/09
to EEGUI
Wow, not a whole lot of activity here, hopefully Jared is still
popping in here on occassion.

I have a ComboBox control and I can't quite get it to function right.
When an item in it is clicked, it's supposed to do the following...

cbFrames.Text = sFrame & " Frame"
cbFrames.List.Visible = False

Where "sFrame" is a variable passed in based on which item in the
combo box is clicked.

The problem is, this behavior never triggers on the first click of the
item, only on the second. I'm using the "Triggered" event of the
individual items, as the "Click" one doesn't work at all.

But this is definatley weird...on the first click, the text of the
combo box doesn't change but the list itself disappears. Its only on
the 2nd click that I get the expected behavior.

Should I be calling a different method? Should I be calling something
within the combo box control itself, rather than individual items?

Help!

Jared Mark

unread,
Aug 19, 2009, 1:11:41 PM8/19/09
to ee...@googlegroups.com
Sorry this took so long... I flagged this email to make a mental note to
respond to it, then it completely slipped my mind.

To answer your question: Handle the event ComboBox.SelectedItemChanged


Private Sub MyEventHandlerSub(ByVal SelectedItem as guiControlBase) Handles
MyComboBox.SelectedItemChanged
cbFrames.Text = sFrame & " Frame"
End Sub

Note, you don't have to mess with the list.visible stuff... the combo box
handles that automatically.

Jared Mark
Technical Support and VB.NET Programmer

Javier Ramirez

unread,
Aug 19, 2009, 2:25:22 PM8/19/09
to EEGUI
I'm missing something obvious here, aren't I?

So i have the "SelectedItem", which in this case is a button. How do
I get the "Text" property of the button from the SelectedItem? I'm
thinking its a cast or something like that but can't pin it down.
> Help!- Hide quoted text -
>
> - Show quoted text -

Jared Mark

unread,
Aug 19, 2009, 4:41:59 PM8/19/09
to ee...@googlegroups.com
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!

Javier Ramirez

unread,
Aug 20, 2009, 2:14:22 PM8/20/09
to EEGUI
Thanks Jared! Appreciate the info!
> > - Show quoted text -- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages