Hallo there,
I have a form with a button and a listview on it. I wanna pass this form to a function. In that function i will need to get all the objects from the form (button and listview) but i dont know how to get hem.
Some advice?
Greetz
Cheyloe
Printable View
Hallo there,
I have a form with a button and a listview on it. I wanna pass this form to a function. In that function i will need to get all the objects from the form (button and listview) but i dont know how to get hem.
Some advice?
Greetz
Cheyloe
you mean something like this...
VB Code:
[Color=Blue]Private[/color] [Color=Blue]Sub[/color] Button1_Click([Color=Blue]ByVal[/color] sender [Color=Blue]As[/color] System.Object, [Color=Blue]ByVal[/color] e [Color=Blue]As[/color] System.EventArgs) [Color=Blue]Handles[/color] Button1.Click getObjects([Color=Blue]Me[/color]) [Color=Blue]End[/color] [Color=Blue]Sub [/color] [Color=Blue]Private[/color] [Color=Blue]Function[/color] getObjects([Color=Blue]ByVal[/color] f [Color=Blue]As[/color] Form1) [Color=Blue]Dim[/color] ctl [Color=Blue]As[/color] Control [Color=Blue]For[/color] [Color=Blue]Each[/color] ctl [Color=Blue]In[/color] f.Controls Console.WriteLine(ctl.Name) [Color=Blue]Next [/color] [Color=Blue]End[/color]
Here is a Function that will loop through all the controls on the Form that is passed to the Function.
OR...Code:Private Function GetControls(ByVal MyForm As Form)
Dim strControls As String
Dim I As Integer
For I = 0 To MyForm.Controls.Count - 1
strControls += MyForm.Controls.Item(I).ToString & vbNewLine
Next
MessageBox.Show(strControls)
End Function
Code:Private Function GetControls(ByVal MyForm As Form)
Dim strControls As String
Dim I As Control
For Each I In MyForm.Controls
strControls += I.ToString & vbNewLine
Next
MessageBox.Show(strControls)
End Function