[Gambas-user] ComboBox options from databse
timothy
timothy.marshal-nichols at ...247...
Mon Sep 10 14:56:11 CEST 2007
> -----Original Message-----
> From: gambas-user-bounces at lists.sourceforge.net
> [mailto:gambas-user-bounces at lists.sourceforge.net] On Behalf
> Of Eduardo Huertas
> Sent: Sunday, 09 September 2007 11:55 PM
> To: mailing list for gambas users
> Subject: Re: [Gambas-user] ComboBox options from databse
>
>
> Thanks for the quick answer. There must be something I am missing...
>
> I have been playing with the idea you sent, but I get to the
> point where I have to add the values to the ComboBox. As far
> as I have read, the way to do it is... SUB Add ( Item AS
> String [ , Index AS Integer ]
>
> So, the method is wants a String, and will not accept a String[]
> (array) as the first parameter.
>
> What am I missing?
>
> 2007/9/9, ron <ronstk at ...239...>:
> > I did put the id,item in a array and fill the combobox from this
> > array.
> >
> > DIM id_item as object[]
> > dim it as string[]
> >
> > for i = 0 to recordcount-1
> > it=new string[]
> > it[0]=result.field["id"]
> > it[1]=result.field['item"]
> > ad_item.add(it)
> > next
> >
> > The index from the combobox is the entry in id_item array
> This way you
> > can even use more as 2 fields to get from the array
> >
> > index is sequential and id can be with missing numbers this way.
>
If you fill your Result object from the database:
resultTable = <some code to fill result from database>
And then fill your ComboBox with the required field:
ComboBox1.Clear()
IF NOT resultTable.MoveFirst() THEN
REPEAT
ComboBox1.Add("item")
UNTIL resultTable.MoveNext()
END IF
The Index property of the ComboBox and the Result object should refer to
the same record. Note this is the Index property - not the ID field in
the database table. The latter could, of course, be totally different.
So you should be able to get the database ID (and other fields) for
record by moving the Result index to the same index as the ComboBox:
PUBLIC SUB ComboBox1_Click()
resultTable.MoveTo(ComboBox1.Index)
PRINT resultTable["ID"]
END
For the above to be true:
A) Do not sort the ComboBox
B) Edit the result object, above all by deleting records.
Thanks
8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>
More information about the User
mailing list