Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data source of a combo box 3

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
Ok, I have been thoroughly frustrated with combo boxes for some time now. They never seem to behave the way I expect them to. I can't even remember all the problems I've had that I ended up giving up on and trying a different way. In any case, here's my latest.

In the init event of the combo box, I create a public array of 15 rows and 2 columns. I use a FOR i=1 to 15...NEXT loop to populate the second column (i,2) with (i-1) so I get the numbers 0 to 14 in it, numeric type. I then assign column 1 of each with a different character string.

I set the combo box to have 2 columns, boundcolumn of 2. It displays the character string, but the Value property returns the number...except that the number is of type C!? And no matter what I try, the combo box starts BLANK, on a non-existant 16th entry at the bottom of the list which disappears as soon as I pick a different entry. And, again, the Value property and any variable I assign to the ControlSource returns the right number, but it's of type C.

When I used RowSourceType 1 and populated the combobox with a comma delimited string, it worked fine, and I set the initial item with the line THIS.VALUE='All', 'All' being the character string of the first item. But I don't want the control to return a character string...I want it to return the number in the second column of the array.

Any ideas? I have yet to get a combo box to behave the way I thought it should...and most of the property descriptions under the Data tab don't make much sense to me.
 
I think you have to set the 'Bound To' property of the combo box to to 'true' and initialise your 'ControlSource' to the value you want.

Wayne
 
chpicker, you're not alone with the problems with combobox ;) However, it will never be used if it is so bad, indeed.

The first thing you should remember that combobox works only with character data in the list. If you populate its list by other data, they're automatically converted to the character in the combobox.list[] array. That has the workaround though. Make your own combobox class. In the Valid event of the combobox put following:
if this.ListIndex>0
if '.' $ this.CustomControlSource
replace (this.CustomControlSource) ;
with val(this.List[this.ListIndex,this.BoundColumn])
else
replace (this.CustomControlSource) ;
with val(this.List[this.ListIndex,this.BoundColumn]) ;
in (left(this.CustomControlSource, ;
AT('.',this.CustomControlSource)-1))
endif
endif

And in the Refresh event/method of the combobox put following:

this.Value = str(eval(this.CustomControlSource))

Than leave the ControlSource property empty and fill CustomControlSource property instead. You can define also _Assign method for ControlSource property to redirect any change of control source to the custom control source.

After each requery() call also Refresh() of the combobox.


Above is a pure custom binding to the data.

Hope this helps.

Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Thanks for the explanation, Vlad. Your sig line kinda hit home here, too, hehe. Since my BoundColumn=2, indicating the numeric value, the Value property needs to be set to '0', not 'All'...and the reason this wasn't working was because I had left "Combo1.Value='All'" in my Form.Init method. *smacks forehead*

Anyway, I can deal with the control source returning a character string, that's easy to handle. I didn't know that it has to be character data. Thanks!
 
Note that when you use numeric value, it is not really the value in the bound column, it is a value of the ListIndex. If BoundTo = .T., Value automatically becomes character properly to the BoundColumn (as far as I know).
Vlad Grynchyshyn
vgryn@softserve.lviv.ua
The professional level of programmer could be determined by level of stupidity of his/her bugs
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top