|
-
Feb 23rd, 2010, 09:10 PM
#1
Thread Starter
Fanatic Member
[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!
-
Feb 23rd, 2010, 09:17 PM
#2
Re: Get control collection from mdi active child form
That would be its Controls property.
-
Feb 23rd, 2010, 09:34 PM
#3
Thread Starter
Fanatic Member
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:
Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs) Handles NewToolStripMenuItem.Click, NewToolStripButton.Click, NewWindowToolStripMenuItem.Click ' Create a new instance of the child form. Dim ChildForm As New System.Windows.Forms.Form ' Make it a child of this MDI form before showing it. ChildForm.MdiParent = Me m_ChildFormNumber += 1 ChildForm.Text = "Untitled " & m_ChildFormNumber ChildForm.Controls.Add(New UserControl) ChildForm.Show() 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.
-
Feb 23rd, 2010, 10:01 PM
#4
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.
-
Feb 23rd, 2010, 11:06 PM
#5
Thread Starter
Fanatic Member
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).
-
Feb 23rd, 2010, 11:09 PM
#6
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.
-
Feb 23rd, 2010, 11:13 PM
#7
Thread Starter
Fanatic Member
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!
-
Feb 23rd, 2010, 11:44 PM
#8
Thread Starter
Fanatic Member
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:
Public Class Form2 Public ReadOnly Property Author() As String Get Return UC.TextBox1.Text End Get End Property Public ReadOnly Property Title() As String Get Return UC.TextBox2.Text End Get End Property Public ReadOnly Property Notes() As String Get Return UC.TextBox3.Text End Get End Property End Class
How would I access these in the parent form? Like so?
vb.net Code:
Private Sub SaveToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles SaveToolStripButton.Click, SaveToolStripMenuItem.Click Dim _author As String = Form2.Author Dim _title As String = Form2.Title Dim _notes As String = Form2.Notes 'Do something with them End Sub
-
Feb 25th, 2010, 07:40 AM
#9
Thread Starter
Fanatic Member
Re: [RESOLVED] Get control collection from mdi active child form
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|