Results 1 to 3 of 3

Thread: Get all objects from a form?

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2003
    Posts
    3

    Get all objects from a form?

    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

  2. #2
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    you mean something like this...
    VB Code:
    1. [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
    2.         getObjects([Color=Blue]Me[/color])
    3.     [Color=Blue]End[/color] [Color=Blue]Sub
    4.  
    5. [/color]    [Color=Blue]Private[/color] [Color=Blue]Function[/color] getObjects([Color=Blue]ByVal[/color] f [Color=Blue]As[/color] Form1)
    6.         [Color=Blue]Dim[/color] ctl [Color=Blue]As[/color] Control
    7.  
    8.         [Color=Blue]For[/color] [Color=Blue]Each[/color] ctl [Color=Blue]In[/color] f.Controls
    9.             Console.WriteLine(ctl.Name)
    10.         [Color=Blue]Next
    11.  
    12. [/color]    [Color=Blue]End[/color]
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  3. #3
    Hyperactive Member
    Join Date
    May 2002
    Location
    Wisconsin, USA
    Posts
    279
    Here is a Function that will loop through all the controls on the Form that is passed to the Function.

    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
    OR...

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width