I use this code (Obviously, without creating a custom combo):

Public Sub LoadCombo()
Dim aIDs As New Integer[]
Dim sQuery As New String

  cboSample.Clear

  ' Load Data
  hResult = $hConn.Exec("select ID, desc from MyTable")
  For Each hResult
    cboSample.Add(hResult!desc)
    aIDs.Add(hResult!ID)
  Next
  cboSample.Tag = aIDs

End

Public Sub cboSample_Change()
  If cboSample.Index > -1 Then
    Message("ID associated with '" & cboSample.Text & "': " &
cboSample.Tag[cboSample.Index])
  Endif
End

Regards

*_________________________*
*Lic. Daniel Quintero Rojas*

*¡Saludos desde México!________*



On Mon, Mar 3, 2014 at 1:55 PM, Tobias Boege <tabo...@gmail.com> wrote:

> On Mon, 03 Mar 2014, Matti wrote:
> > 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
> >
>
> You could have a
>
> Private $aTags As New Variant[]
>
> in your class which associates a Variant with an item via the item's index.
> You need to maintain that array, though. Watch out for the Add(), Clear()
> and Remove() methods and the List property! I'm not familiar with the
> sources, so I don't know if there is a smarter way (and I'm assuming that
> you write the extended ComboBox in Gambas).
>
> Regards,
> Tobi
>
> --
> "There's an old saying: Don't change anything... ever!" -- Mr. Monk
>
>
> ------------------------------------------------------------------------------
> Subversion Kills Productivity. Get off Subversion & Make the Move to
> Perforce.
> With Perforce, you get hassle-free workflows. Merge that actually works.
> Faster operations. Version large binaries.  Built-in WAN optimization and
> the
> freedom to use Git, Perforce or both. Make the move to Perforce.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
> _______________________________________________
> Gambas-user mailing list
> Gambas-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/gambas-user
>
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to