Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
List - selected item
Message
 
To
04/11/1996 10:36:39
General information
Forum:
Visual FoxPro
Category:
Forms & Form designer
Miscellaneous
Thread ID:
00011428
Message ID:
00011944
Views:
23
>How do I programmatically change the selected item on a list control, when I do not know the IndexID?

I know this is a very late response, but I was away for a while. :)

Another way to select an item in a listbox programatically is to set the Value property to the value of whatever column the listbox is bound to.
I always set up my listboxes so that the cursor contains the primary key as one of the columns (usually not displayed), and I bind the listbox to that column. Then I can select a particular item by setting the Value property of the listbox to the primary key. This will select that item.

A couple of caveats, though:

1) Even if your primary key value is numeric, the listbox will convert it to a character string, so you need to make sure you convert to character when you set the Value. Something like ....

ThisForm.MyListBox.Value = LTRIM(STR(nCust_Id))

2) This will create some strange behavior if your listbox allows MultiSelect, so I wouldn't advise it in that case.

So a brief example would be:

*-- Create your cursor
SELECT Name, Cust_Id FROM Customer INTO CURSOR TempCust
*-- Bind the listbox to the cursor
ThisForm.MyListBox.RowSourceType = 6
ThisForm.MyListBox.RowSource = "TempCust.Name, Cust_Id"
*-- Bind the Value property to the second column (Cust_Id)
ThisForm.MyListBox.Bound = 2
*-- Select an item
nCust_Id = 6
ThisForm.MyListBox.Value = LTRIM(STR(nCust_Id))

Hope this is helpful.

Mark
=========================
Mark A. Peter
Los Angeles, CA
mpeter@primenet.com
=========================
Previous
Reply
Map
View

Click here to load this message in the networking platform