I wonder how do I reference the user form in which the sender control is located? I have a programmatically created button control and user form in which it's located and when clicking on it I need to reference the user form to grab a value from a combobox in that form to use it as a variable and I can do it descending i.e. get the sub control of the sender but how do you get the control above the sender?
Sub DynamicForm_NewForm_SmartHUB_ProjectsActivated(ByVal sender As Object, ByVal e As EventArgs)
strProjectTypeFolderName = '(form in which the sender is located).combobox_ProjectType.selecteditem
End Sub
You'd first need to cast the
senderasControlat least. You can then access theParentproperty, although that property is typeControland may not be a form, if thesenderis in aPanel,GroupBoxor some other container. You ought to call theFindFormmethod instead. It will return aFormreference and it will also get the containing form no matter how deeply thesenderis nested.If you have
Option Strict On, which you probably don't but you definitely should, even aFormreference won't be sufficient. TheFormclass has nocombobox_ProjectTypefield, so you'd need to cast it as it's actual type -Form1or whatever - in order to access that field without using late binding.