-1

Textbox.text I want to access. And I want it user-configurable before I want to access the altered text.

Dim qbox As New TextBox
        qbox.Size = New Size(20, 20)
        qbox.Location = New Point(90, 10)
        qbox.Parent = addtocart
        qbox.Name = "quarts"
        qbox.Text = "ss"**

how I dynamically add it inside a series of other dynamic controls:

tile.Controls.Add(addtocart)
            flpp.Controls.Add(tile)
        tile.Controls.Add(plabel)
        tile.Controls.Add(nlabel)
        addtocart.Controls.Add(qbox)

How I tried to access it:

qb.Text = CType(Me.Controls("flpp").Controls("tile").Controls("addtocart").Controls("qbox"), TextBox).Text

I generated to textbox at runtime. Of course it's dynamic. I'm new to VB and I'm just experimenting a school project. I wanted the textbox text to be configurable and then access that configured value. I've been brain-cracking for days about this. when I run the thing, I "getObject reference not set to an instance of an object." under NullReferenceException was unhandled" something like this. I don't get it.

1 Answers1

0

WinForms? If yes, and you want to find that control "by name", then use the Controls.Find() function:

Dim ctlName As String = "quarts"
Dim matches() As Control = Me.Controls.Find(ctlName, True)
If matches.Length > 0 AndAlso TypeOf matches(0) Is TextBox Then
    Dim tb As TextBox = DirectCast(matches(0), TextBox)
    ' ... use "tb" somehow ...
    Dim value As String = tb.Text
    MessageBox.Show(value)
End If
Idle_Mind
  • 38,363
  • 3
  • 29
  • 40