[Gambas-user] ComboBox options from databse

timothy timothy.marshal-nichols at ...247...
Tue Sep 11 07:23:23 CEST 2007



> 
> 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...>
> 
> 

There is an error in my example for loading the ComboBox. The above will
just keep adding the string "item". Not very useful!

You should add the item from the result object. The example should be:

	ComboBox1.Clear()
 	IF NOT resultTable.MoveFirst() THEN
 		REPEAT
 			ComboBox1.Add(resultTable["item"])
 		UNTIL resultTable.MoveNext()
 	END IF

I should have copied and pasted, rather than write it out again. Sorry.

Thanks

8-{)} Timothy Marshal-Nichols
<mailto: timothy.marshal-nichols at ...247...>






More information about the User mailing list