Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combobox looses it's ID
Message
From
15/12/2001 07:07:52
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
14/12/2001 13:43:52
General information
Forum:
Visual FoxPro
Category:
Troubleshooting
Miscellaneous
Thread ID:
00594525
Message ID:
00594781
Views:
28
This message has been marked as a message which has helped to the initial question of the thread.
>>>Hi All,
>>>
>>>I have a combobox that is populated by an array. 2 columns. Employee name & number. The combobox is bound to the 2nd column. the array is ordered by the employee names. So the numeric 2nd column is not in sequential order. Everything has been going well until someone decided that there should be an internal number -1. When I select that employee there is code in the valid event to retrieve the required data. The last line in the event is a form.refresh. When the refresh is finished. all other controls on the form display the correct data. But the combobox no longer displays the employee's name. The combobox.value has not changed. Neither has the value of the controlsource. But the combobox.listitemid has. What happened?
>>>
>>>VFP6 SP5
>>>
>>>TIA
>>>Mike
>>
>>Michael,
>>Set BoundTo = .t.
>
>It is. See above.
>
>>Better use an SQLRowsourcetype and directly use cursorname.id
>>Cetin
>
>Never tried that before. But I'll try now
>
>Thanks.
>Mike

Mýke,
I couldn't see BoundTo = .t. in your message. I don't mean BoundColumn. When boundcolumn has numeric values it's important you use BoundTo. Otherwise those numeric values are a headache especially if you had ids like 23,45 etc instead of filling a sequence from 1 to up.
However it wouldn't be a problem if you didn't assign a controlsource (you assigned as I got). If that's true why ? On purpose might be but it would change the id of current record. Hope I'm wrong here.
For SQL rowsource thing it's easier to manage and pointer in SQL cursor 'moves' as you select in combo. You're free to have as many fields as you like in cursor and yet could set columncount to any value you wish. ie:
*Form.load
select * from employee where .f. into cursor dummy nofilter
afields(arrDummy)
create cursor crsDummy from array arrDummy
insert into crsDummy (emp_id) values (-1) && Assuming it was integer
use in 'Dummy'
* Combo.init
* First expression serves as display value
* 2nd as boundcolumn when we don't know the actual columnorder
* of emp_id - if we ever needed a boundcolumn
* 3rd is for sorting by uppering
* Assuming we might need boundcolumn only 2 columns need to be in combo 
lcSQL = 'select last_name-(", "+first+name) as cname,emp_id as pid,'+;
           'upper(last_name+first+name) as sorter,* from crsDummy '+;
        'union '+;
        'select last_name-(", "+first+name) as cname,emp_id as pid,'+;
           'upper(last_name+first+name) as sorter,* from employee '+;
          'where blahblahforsecondcursor '+;
        'order by 3 '+;
        'into cursor crsMyCombo'
with this
  .Rowsourcetype=3
  .Rowsource=lcSQL
  .Columncount = 2 && Only display value and boundcolumn
  .Columnwidths = '100,0' && Also suppress id display 
  .BoundColumn = 2
  <b>.BoundTo=.T.</b> && Have a numeric boundcolumn and might have any number 
  .ControlSource = 'Something' && Have boundcolumn so it should be for this
endwith
Whenever a selection is made in combo we're on the record it corresponds to in 'crsMyCombo'. Whenever we need value we could directly query :
crsMyCombo.pid or crsMyCombo.emp_id
Could still get something other than that from any field of cursor.ie :
crsMyCombo.ReportsTo

IMHO this is one of most flexible RowSourceType for combo and listboxes.
SQL is written and assigned once in init. It could have a where clause referencing 'in scope' variables (typically form elemenst) :
'where First_Name = thisform.txtFirst.Value'
or ;
'where ReportsTo = thisform.Supervisor'
You change Supervisor property value and call :
thisform.myCombo.requery()
to repopulate with criteria and refresh maybe.

ControlSource assignment have advantage of automatically showing related displayvalue in combo OTOH it has the danger unintentionally changing id of current record. Instead to change display value :

select crsMyCombo
locate for emp_id = myTable.emp_id

would do the trick safer. In that case you would remove ControlSource and boundcolumn properties which you don't need.

BUT if combo was the 'navigator' control w/o doing that in its valid, have controlsource and bounto, boundcolumn and use RowSourceType = 'Fields'. That would cause combo selection 'navigate' in original table.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform