-
Apr 17th, 2024, 07:10 AM
#1
RC6 & VB6: Question: Populating a DropDownList with Data rather than key...
Olaf, can you please show me how to populate a dropdown list from a collection and display the data?
Code:
Public collValidLocations As cCollection
Set collValidLocations = New_c.Collection(False)
For i = 0 To UBound(icaoDataArray) - 1 Step 1
.
. blah blah blah
.
thisKey = "key" & CStr(searchCount)
collValidLocations.Add retStr, thisKey ' key is the search count, returning a collection of matching locations
next i
I am populating a RC collection as above. All good.
I use the collection to populate a VB6 drop down combobox as follows:
Code:
For i = 0 To cnt - 1
cmbMatchingLocations.AddItem collValidLocations("key" & CStr(i + 1)) ' the cnt is the key
cmbMatchingLocations.ItemData(i) = i
Next i
cmbMatchingLocations.ListIndex = 0 ' the default entry


This works. I wish to replicate what I see in the VB6 form above using an RC dropDownList but I can currently only make it display the key
I require it to display the data as above.
Code:
Public WithEvents sCmbMatchingLocations As cwDropDownList
Set sCmbMatchingLocations = fSelector.SelectorForm.Widgets.Add(New_W("cwDropDownList"), "sCmbMatchingLocations", 120, 58, 225, 28)
sCmbMatchingLocations.Widget.FontSize = 15
sCmbMatchingLocations.Widget.FontName = "times new roman"
sCmbMatchingLocations.Widget.Alpha = 0.5
sCmbMatchingLocations.DropDown.Caption = "ICAO"
sCmbMatchingLocations.SetDataSource collValidLocations, "collValidLocations"


Following examples I have used the SetDataSource method but using the method above I can only display the key in the dropdown, it is not clear to me from extant examples what I need to do to display the associated data. Basically, I want the dropdown list to show the data and not the key.
I was hoping that the sCmbMatchingLocations collection had some option that would allow the data to be shown rather than the key but I cannot for the life of me fathom the various switches without documentation, I cannot find real-life examples that do what I want. Perhaps I am doing it incorrectly, I can accept that. I am struggling with a simple dropDownlist as it works so differently from the VB6 version that I am familiar with.
Do I have to read the data in line by line as per the old VB6 method or does SetDataSource have some configuration that I am unaware?
Last edited by yereverluvinuncleber; Apr 17th, 2024 at 07:28 AM.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Apr 17th, 2024, 09:38 AM
#2
Re: RC6 & VB6: Question: Populating a DropDownList with Data rather than key...
 Originally Posted by yereverluvinuncleber
Olaf, can you please show me how to populate a dropdown list from a collection and display the data?
Code:
Public collValidLocations As cCollection
Set collValidLocations = New_c.Collection(False)
For i = 0 To UBound(icaoDataArray) - 1 Step 1
.
. blah blah blah
.
thisKey = "key" & CStr(searchCount)
collValidLocations.Add retStr, thisKey ' key is the search count, returning a collection of matching locations
next i
In the above Add-Method, the later "Item-Text" of the DropDown -
needs to be passed in the second (the Key-) Parameter.
Whereas the first one (the Value) will receive the associated "ItemData".
Code:
Public collValidLocations As cCollection
Set collValidLocations = New_c.Collection(False)
For i = 0 To UBound(icaoDataArray) - 1 Step 1
.
. blah blah blah
.
collValidLocations.Add i, retStr 'i = ItemData, retStr = Key (which will become Item-Text in the cwDropDown)
next i
If you use the above (differently filled) cCollection to populate a VB6 drop down combobox,
you will have to change that code as follows:
Code:
For i = 0 To cnt - 1
cmbMatchingLocations.AddItem collValidLocations.KeyByIndex(i)
cmbMatchingLocations.ItemData(i) = collValidLocations.ItemByIndex(i)
Next i
cmbMatchingLocations.ListIndex = 0 ' the default entry
HTH
Olaf
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
|