|
-
Jun 3rd, 2001, 07:00 AM
#1
Thread Starter
Lively Member
Two combo box questions
1. I want to have some 'hidden' values attached to my combo box. Basically, there are 3 fields I want the user to select (say Name, Code, Country), but I only want to show the Name in the combo box. The details are held in a DB but there may be duplicate Name fields, so I can't use a FindFirst method to get the record the user has chosen.
I was contemplating 2 arrays which are filled at the same time as the combo box, and then using ListIndex to retrieve the row of the array, but I'm not sure that's the best way.
2. What is the difference between
Code:
combo1.List(combo1.ListIndex)
and assuming that combo1 is set to the correct style (offhand I can remember that one of the styles doesn't allow you to retrieve the text property, I think)
-
Jun 3rd, 2001, 07:12 AM
#2
If your database table has an ID field (l;ike an Autonumber in Access, or Identity filed in SQL Server), then you can stroe that in the combo boxes item data, and retrieve the record based on the ID.
As for the difference between text and list, text only works when the combo style is not 2 - DropdownList
- gaffa
-
Jun 3rd, 2001, 07:12 AM
#3
Addicted Member
1) Assuming that you have an autonumber Primary Key in the table, which you should, the use the Itemdata property of Combo.
Then seek on the Primary Key instead, it will be faster than a text field also.
2)They will both accomplish the same thing.
-
Jun 3rd, 2001, 07:20 AM
#4
1. I would add a auto numbering field to the database so each row has an unique number associated to it. I would then use the ItemData property of the combo box and add the number to that.
In that way you can simply look up the right row in the database.
2. The difference between using the Text property or the List property is that if the user types in it's own text in the Combo the ListIndex property will be -1 so you can't look up the value with Combo1.List(Combo1.ListIndex).
The Text property can be used with all styles of the combo but when the style property is set to 2 - Dropdown List the property is Read-Only.
It's also slightly faster to use the Text property because the List(ListIndex) call require VB to read two properties.
Best regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|