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)
panelName.Add(Panel1)
panelName.Add(Panel2)
panelName.Add(Panel3)

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

Recommended Answers

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", …
Jump to Post

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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.