[Gambas-user] Building a custom MyComboBox

Benoît Minisini gambas at ...1...
Mon Mar 3 21:53:41 CET 2014


Le 03/03/2014 20:49, Matti a écrit :
> I'm playing around with a ComboBox that should have some special features.
> Looked into the sources and found out how to create and inherit it.
> Subs, Functions and Events  work.
>
> But one thing is a complete riddle to me:
> In the wiki, it says: "For example, you can create a custom MyListBox class that inherits ListBox <http://gambasdoc.org/help/comp/gb.qt/listbox?view> but allows to associate a tag with each list item."
> That's exactly what I'd need for MyComboBox: each list item with a tag (ID from a database).
>
> Could someone give me a hint how to do that?
> Thanks, Matti
>

If you create a class named ComboBox in your project, and if you export 
that class, it will extend the native ComboBox class located in the GUI 
component.

That way, by redefining the Add(), Clear(), _get()... methods (i.e. 
every method that read or write a ComboBox list element), and by using 
the SUPER keyword to call the methods of the overriden class when 
needed, you can add support for an item index associated with the item text.

If you want to keep the original ComboBox class, just use another name, 
but then add "Inherits ComboBox" to that class.

Regards,

-- 
Benoît Minisini




More information about the User mailing list