Results 1 to 9 of 9

Thread: [RESOLVED] Get control collection from mdi active child form

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Resolved [RESOLVED] Get control collection from mdi active child form

    Hi,

    After getting the current mdi active child form, how can I get it's control collection so I can access their data?

    Thanks in advance!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Get control collection from mdi active child form

    That would be its Controls property.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Get control collection from mdi active child form

    Yes, sorry, I now see I have explained myself poorly.

    I have a MDI form, which adds a user control (which has three textboxes) in each MDIChildForm. When adding the control I create a new instance like so:

    vb.net Code:
    1. Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click
    2.         ' Create a new instance of the child form.
    3.         Dim ChildForm As New System.Windows.Forms.Form
    4.         ' Make it a child of this MDI form before showing it.
    5.         ChildForm.MdiParent = Me
    6.  
    7.         m_ChildFormNumber += 1
    8.         ChildForm.Text = "Untitled " & m_ChildFormNumber
    9.  
    10.         ChildForm.Controls.Add(New UserControl)
    11.         ChildForm.Show()
    12.     End Sub

    I want to get the control collection to harvest the data inputed by the user in each textbox. I had created read only properties in the user control so it would be easier, but, for some reason, when reading it comes back empty.
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Get control collection from mdi active child form

    Why create Form instances like that? Why not design a form that already has the UC on it and then just create instances of that? You can then add properties to that form that will expose the data from the UC.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Get control collection from mdi active child form

    If I understand correctly you mean create a Form2 with the user control and use that form as a child of Form1 (or main form) and then get the data how? (I'm sorry, I'm really lost with getting the data).
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Get control collection from mdi active child form

    No you're not. You've already done it. You said yourself that you declared ReadOnly properties in the UserControl so you could get the data. If you get the data from the UC from properties, how do you suppose you get it from the form? You guessed it: properties. Whatever properties you have on the UC, you declare the same properties on the form. The form properties then simply pass through the UC properties, just as the UC is probably passing through the properties of its children.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Get control collection from mdi active child form

    So all I have to do is get the property of the active window and voilà ! THANKS!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: Get control collection from mdi active child form

    This how I've set the property of the UC and the second form: (In the UC, would be 'Me' instead of UC)

    vb.net Code:
    1. Public Class Form2
    2.     Public ReadOnly Property Author() As String
    3.         Get
    4.             Return UC.TextBox1.Text
    5.         End Get
    6.     End Property
    7.  
    8.     Public ReadOnly Property Title() As String
    9.         Get
    10.             Return UC.TextBox2.Text
    11.         End Get
    12.     End Property
    13.  
    14.     Public ReadOnly Property Notes() As String
    15.         Get
    16.             Return UC.TextBox3.Text
    17.         End Get
    18.     End Property
    19. End Class

    How would I access these in the parent form? Like so?

    vb.net Code:
    1. Private Sub SaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveToolStripButton.Click, SaveToolStripMenuItem.Click
    2.         Dim _author As String = Form2.Author
    3.         Dim _title As String = Form2.Title
    4.         Dim _notes As String = Form2.Notes
    5.  
    6.         'Do something with them
    7.     End Sub
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Re: [RESOLVED] Get control collection from mdi active child form

    Thanks! I've got it now!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

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