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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Dataview Name From Array of Dataviews 1

Status
Not open for further replies.

Auguy

Programmer
May 1, 2004
1,206
US
I have an array of data views constructed like this where the three data views have already been created.
Code:
    dvList(0) = CompanyMasterView
dvList(1) = LeaseTypeView
dvList(2) = GroupView
I'm using this array to assign the data source for combo boxes added at run time. Right now I'm using the array position (DataSourceNbr1 = 0,1,2) stored in my table to assign the data source. DisplayMember1 & ValueMember1 are also stored in my table.
Code:
PnlCombo.cboBox1.DisplayMember = DisplayMember1
PnlCombo.cboBox1.ValueMember = ValueMember1
PnlCombo.cboBox1.DataSource = dvList(DataSourceNbr1)
I would like to just use the data view name I have stored in the table to find the correct index (0,1,2) in dvList, but I can't seem to find a way to get the data view name from the array dvList. Is there a way to do this?

Auguy
Sylvania/Toledo Ohio
 
To do this, use a Collection instead of an Array.

Code:
Dim dvColl As Collection

dvColl = New Collection

dvColl.Add(CompanyMasterView, "Key 1")
dvColl.Add(LeaseTypeView, "Key 2")
dvColl.Add(GroupView, "Key 3")

PnlCombo.cboBox1.DisplayMember = DisplayMember1
PnlCombo.cboBox1.ValueMember = ValueMember1
PnlCombo.cboBox1.DataSource = [red]dvColl("Key 1")[/red]

As the code shows, Collections have a value and a key, and you can reference the value via the key, which is exactly what you want. You can use the DataView's name as the Key.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Thanks! That will help a lot. BTW, this question is a follow up on another question you answered a few years ago. thread796-1691914 I finally had time to got it working and this final piece will complete the code. Thanks again!

Auguy
Sylvania/Toledo Ohio
 
Thanks Jebenson, just finished the code using the collection, works perfectly. Thinking about where else I can use collections

Auguy
Sylvania/Toledo Ohio
 
Awesome!

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top