0

I'm new to vb.net and theirs problibly a easy answer. I am trying to get values from all the textboxes in my program. and I am looping through all of my textboxes with the name of the textbox in a string. So how do you get the text with only the name of the element in a string? I am also working on a wpf app.

thank-you much.

2 Answers2

1

You could instead use this approach to loop through all your textboxes:

For Each txtBox As TextBox In MyPanel.Controls.OfType(Of TextBox)()
    Dim txt As String = txtBox.Text
    'Do whatever
Next

If you really want to get a control from a string (keep in mind that it is very error-prone) then you should check out CType:

Dim txtBox As TextBox = CType("TextBox1", TextBox)
Viktor Ek
  • 353
  • 1
  • 13
0

If you really use Name property to find textbox object, this question may help: Find WPF control by Name

But to me the case is rare. When you name a user control, you would refer it as a named object.

Community
  • 1
  • 1
dytori
  • 487
  • 4
  • 12