Hello Community,
I would like to know if there is a way to get the corresponding list index of another list like below:

Dim panelTitle As New List(Of String)
panelTitle.Add("First Panel")
panelTitle.Add("Second Panel")
panelTitle.Add("Third Panel")

Dim panelName As New List(Of Panel)

So when I choose "Second Panel" I want the returned panel in this case I want it to be "Panel2".

Recommended Answers

All 2 Replies

A Dictionary(Of String, Panel) would work here:

Dim PanelCollection As New Dictionary(Of String, Panel)
Dim newpanel As New Panel With {.Name = "Panel1"}
PanelCollection.Add("First Panel", newpanel)
newpanel = New Panel With {.Name = "Panel2"}
PanelCollection.Add("Second Panel", newpanel)
newpanel = New Panel With {.Name = "Panel3"}
PanelCollection.Add("Thired Panel", newpanel)

Now PanelCollection("Second Panel") will refer to the panel named "Panel2"

I did think of using a dictionary but it didn't work in the way I wanted it. So I can't be bothered trying to do this the way I wanted to do it, so I'm going to build it the long way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.