[Gambas-user] ComboBox.Add method with index, fails

Mike Brett serif at ...1870...
Fri May 16 13:08:15 CEST 2008


Benoit Minisini wrote:
> On jeudi 15 mai 2008, Mike Brett wrote:
>> The syntax for this is given in the Help as
>>
>> SUB Add ( Item AS String [ , Index AS Integer ] )
>>
>> When I try simply
>> ComboBox.Add("some text")
>> there are no errors.
>>
>> Whenever I try to add an index, such as
>> ComboBox.Add("some text", 127)
>> or even
>> ComboBox.Add("some text", CInt(127))
>>
>> I get
>> QComboBox::insertItem: (unnamed) Index 127 out of range
>> QComboBox::setCurrentItem: (unnamed) Index 0 out of range
>>
>> What am I doing wrong please?
>>
>> Thanks.
>>
>> - Mike Brett - (gambas 2.6.0 on Fedora 8)
>>
> 
> Maybe 127 is greater or equal to the number of items in the ComboBox?
>

I think I was expecting the combobox's index to be a handle pointing 
towards the entries, whereas it seems to be more of a direct sort order. 
That is, it seems you must have an index 0 entry before you add an index 
1 entry; further additions must also be continguous.

I had naively misinterpreted the part of the help instructions which 
reads:- "If Index is specified, then the new item is inserted at the 
Index position, 0 being the first item."

I wanted to fill a combobox with text data, and hold associated primary 
key integers from a database as combobox indeces. The PK integers were 
unique but not in gap-free, ascending order.

The combobox will not tolerate:
* any looping .Add sequence where the index doesn't start at 0
* any gaps in the index sequence.

So this works:

FOR iC = 0 TO 20
Combobox.Add ("something", iC)
NEXT

but causes errors for

FOR iC = 1 TO 20
Combobox.Add ("something", iC)
NEXT

and also for

FOR iC = 0 TO 20
Combobox.Add ("something", iC)
NEXT
FOR iC = 30 TO 40
Combobox.Add ("something", iC)
NEXT

Somewhat unexpected to me this also fails

Combobox.Add ("something", 1)
Combobox.Add ("something", 0)

If someone could please confirm this behaviour is all 'as intended' I'll 
move on and simply use an intersection table to map between the combobox 
index and my PKs.

Thanks - Mike -






More information about the User mailing list