Member Avatar for MonsieurPointer

Hi DaniWebbers,

I would like to map a string to a Property using the Dictionary class. For example, I want to map "port" to a textbox's Text property, e.g. myDict.Add(tbPort.Text, "port"). How would I go about defining the dictionary? I've tried the following:

  • Private myDict As Dictionary(Of Property, String)
  • Private myDict As Dictionary(Of [Property], String)

but these do not work, since Property is not a type.

Is this even possible? If so, how do I define the dictionary? If not, would I have to go about using reflection?

Recommended Answers

All 3 Replies

You'd have to create the dictionary as

Private myDict As New Dictionary(Of String, Textbox)
myDict.Add("port",TextBox1)

and you could do

myDict("port").Text = "some text"

You can't create a pointer (reference) to a property within an object (or control).

Member Avatar for MonsieurPointer

Thanks for the tip and sorry for the late reply, I did not receive any notification that you have posted something!

No problem. Check your profile to see if you have the following options set

Receive Email from DaniWeb?
Automatically Watch Articles I Post In?

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.