Hardwire options for comboBox

Forums for specific tips, techniques and example code
sit
Posts: 13
Joined: Mon Sep 29, 2014 6:53 pm

Hardwire options for comboBox

Postby sit » Mon Nov 03, 2014 9:55 am

Hi
I was wondering if anyone knows if it is possible to hardwire options in form properties for a comboBox ?

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Hardwire options for comboBox

Postby BeeJay » Mon Nov 03, 2014 11:41 am

It depends on what you mean by 'form properties'.

For example, do you mean is it possible to set the options that appear in the list for a given ComboBox using the Jade Painter, then the answer is that this is not possible for a standard Jade ComboBox. If you want to have several ComboBoxes on several forms all having the same 'default' set of list entries, then you could potentially create your own subclassed control, and populate the entries available in that ComboBox using the windowCreated event on that subclassed control to add the desired 'default' set of list entries.

Alternately, if you want to be able to supply the values to use at runtime via a properties sheet, again you may be able to achieve this via your own designTime property on your own subclassed control.

For the most part, I've never needed/wanted to do this in a real system as you're often populating the entries available in a ComboBox from persistent model objects in your system. For example, a collection of 'code-table' values in a given 'code-table group'.

Cheers,
BeeJay.

sit
Posts: 13
Joined: Mon Sep 29, 2014 6:53 pm

Re: Hardwire options for comboBox

Postby sit » Tue Nov 04, 2014 6:06 pm

Could anyone give me some advice on how to put an attribute instance from a class into a comboBox ?

so far I have been populating my comboBoxes with the addItem function
ex.
comboFrom.addItem("");

but I don't know how to show an attribute instance in the comboBox.

Thanks

User avatar
BeeJay
Posts: 312
Joined: Tue Jun 30, 2009 2:42 pm
Location: Christchurch, NZ

Re: Hardwire options for comboBox

Postby BeeJay » Tue Nov 04, 2014 8:08 pm

Suppose you have the following class structure in your system:

Object
|-- City
|-- Suburb

Suburb has an attribute Suburb::name (String, length 50), and a reference Suburb::myCity of type City inversed to City::allSuburbs of type SuburbDictByName.

SuburbDictByName is a subclass of MemberKeyDictionary with a membership of Suburb and a key of Suburb::name.

For a given City instance, you could display all the Suburbs in that city using as follows:

1. In say the Form::load event, tell the combobox to display all the Suburbs for the City by calling the ComboBox::displayCollection method for that combobox, passing in the City::allSuburbs collection for the relevant City instance in the relevant parameter.

2. Implement the displayRow event for the combobox. It will pass you in the 'Suburb' object for that row from the collection and you can the return the Suburb::name property as the string return for that event. Jade will automatically call this as many times as necessary to fill the scrollarea of the combobox, and then as/when you scroll it will automatically call this method as/when a new entry comes into the visible area.

Check out the Jade help for displayCollection and displayRow methods respectively for more detail on these methods.

Cheers,
BeeJay.

sit
Posts: 13
Joined: Mon Sep 29, 2014 6:53 pm

Re: Hardwire options for comboBox

Postby sit » Tue Nov 04, 2014 9:26 pm

Thanks :)


Return to “Tips and Techniques”

Who is online

Users browsing this forum: No registered users and 4 guests

cron