Am Montag, den 10.08.2009, 19:49 -0700 schrieb Hugo Chillon:
> For people who looks for a combobox to show items from a database table
> column but need combobox returns item_key from another column, this is a
> class for them:
> 
> ' Gambas class file
> '***************************************************************************
> '*  ComboBoxPlus class
> '*
> '* Autor: Hugo Chillon Estefanell
> '* Date: 09/08/2009
> '*
> '* ComboBoxPlus is a class designed to allow a ComboBox works with 2
> '* columns from a database table. First column for the key_item, second
> '* column for the item. Combobox shows item and ComboBoxPlus.ItemId()
> '* returns key_item
> 
> '* This class call a class (MysqlConnection) to access a database and obtain
> '* a Result object with data. You should use your own method to obtain the
> '* Result object
> '**************************************************************************
> 
> PRIVATE cboBase AS NEW Object[]
> PRIVATE cbo AS ComboBox
> 
> 
> PUBLIC SUB _New(combo AS ComboBox)
>     cbo = combo 
> END
> 
> 
> PUBLIC SUB Populate(strTable AS String, strIndex AS String, strValue AS
> String, strWhere AS String)
>     
>     DIM conn AS MysqlConnection
>     DIM strSQL AS String
>     DIM res AS Result
>     
>     strSQL = "SELECT " & strIndex & ", " & strValue & " FROM " & strTable &
> " " & strWhere
>     
>     conn = NEW MysqlConnection
>     res = conn.RunDSQ(strSQL)
>     IF res.Count > 1 THEN 
>         res.MoveFirst
>         cbo.Add("")
>         cboBase.Add(["", ""])
>         DO WHILE res.Available
>             cbo.Add(res[1])
>             cboBase.Add([res[0], res[1]])
>             res.MoveNext
>         LOOP
>     ENDIF
> END
> 
> 
> PUBLIC FUNCTION ItemId() AS Integer
>   
>     DIM intValue AS Integer
>     
>     intValue = cboBase[cbo.Index][0]
>     RETURN intValue
>   
> END

Salut,

did you know that <object>.Tag is not a String

PROPERTY Tag AS Variant
Returns or sets the control tag. 

This property is intended for the programmer and is never used by the
component. It can contain any Variant value.

So you can use an String[] or what ever you need to  store your  
return-values and set it after having filled the combobox to its TAG.

Asked for the value, you return   combobox.tag[combobox.index] 


-- 
Amicalment
Charlie


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Gambas-user mailing list
Gambas-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to