r/visualbasic • • Feb 23 '19

Interacting with programmatically created items

I am fooling around with creating thing dynamically in code(buttons, text boxes, simple thing). So far I understand the very basics of creating them. For example for a combobox I do:

Dim combobox As New ComboBox
            With combobox
                .Location = New Size(20 * i, 20 * i)
                .Name = "Combobox1"
                .Items.Add("one")
            End With
            Me.Controls.Add(combobox)

I put this on a button and it makes the combobox appears. My question is, after its been generated, how can I interact with it?

I have the .name property to label it as Combobox1, but when I try to add something outside of the With|EndWith box that refers to combobox1 I get an error that says it is undefined or unavailable due to protection level.

How can I interact with it once its been created, or is that not something thats done?

6 Upvotes

8 comments sorted by

View all comments

2

u/[deleted] Feb 23 '19

If it's a child in a form you can just do a me.controls("Combobox1")