473,320 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Referencing main app window from a custom control

Hi,

I have a project with an MDI parent form (Main), which can contain any
number of MDI children (Document). The Document form contains several user
controls, designed as separate projects and referenced from the main
project. I originally had one user control doing some dataset loading on its
own, but now I need the same dataset initialized in the same way in two
different places, so I decided to put it in the MDI parent form.

Now, how do I get a reference to that form (named Main) from the control?
I've tried things like,

Idea 1)
Dim MainForm as Main
MainForm = Me.FindForm.MdiParent

but Main is not recognized as a valid type from within the control. I can
use

Dim MainForm as Form

but then it won't let me access the dataset because dsPaperColors is not a
member of System.Windows.Forms.Form. Obviously.

Idea 2)
I also tried adding a module with a property on it of type Main that the
startup form sets to Me on loading (kind of a fake global variable), but I
can't access that module from the control either.

Idea 3)
And I can't add a reference to the main project into the control, because
there is no DLL.

So how shall I go about this? I suppose I could just pass the main MDI
parent form as an argument to the constructor of the control, but that seems
kinda hacky... there should be an easier, IntelliSense-friendly way to do
it.

Apr 8 '07 #1
3 1403
"Peter" <st*****@hotmail.comwrote in message
news:Di********************@newsread2.news.pas.ear thlink.net...
I have a project with an MDI parent form (Main), which can contain any
number of MDI children (Document). The Document form contains several user
controls, designed as separate projects and referenced from the main
project. I originally had one user control doing some dataset loading on
its own, but now I need the same dataset initialized in the same way in
two different places, so I decided to put it in the MDI parent form.

Now, how do I get a reference to that form (named Main) from the control?
I've tried things like,

Idea 1)
Dim MainForm as Main
MainForm = Me.FindForm.MdiParent

Idea 2)
I also tried adding a module with a property on it of type Main that the
startup form sets to Me on loading (kind of a fake global variable), but I
can't access that module from the control either.

Idea 3)
And I can't add a reference to the main project into the control, because
there is no DLL.

I have solved the problem... or at least gotten something to work...

I simply passed the control a reference to the dataset from the Document
form, using MdiParent.dsPaperColors. Perhaps a better option all around.

Apr 8 '07 #2
Peter,

This can be a long thread therefore I start it slowly.

Why a form, one of the goals is in OOP to leave the dataaccess (and even the
middle data hanling) for from the UI (User interface) Therefore a class or a
good written module would do probably a better job here. You can as well use
a module (or shared class) for often done things, and than to instanced
classes for seldon done things.

Just as start for a thaught discussion

Cor

"Peter" <st*****@hotmail.comschreef in bericht
news:Di********************@newsread2.news.pas.ear thlink.net...
Hi,

I have a project with an MDI parent form (Main), which can contain any
number of MDI children (Document). The Document form contains several user
controls, designed as separate projects and referenced from the main
project. I originally had one user control doing some dataset loading on
its own, but now I need the same dataset initialized in the same way in
two different places, so I decided to put it in the MDI parent form.

Now, how do I get a reference to that form (named Main) from the control?
I've tried things like,

Idea 1)
Dim MainForm as Main
MainForm = Me.FindForm.MdiParent

but Main is not recognized as a valid type from within the control. I can
use

Dim MainForm as Form

but then it won't let me access the dataset because dsPaperColors is not a
member of System.Windows.Forms.Form. Obviously.

Idea 2)
I also tried adding a module with a property on it of type Main that the
startup form sets to Me on loading (kind of a fake global variable), but I
can't access that module from the control either.

Idea 3)
And I can't add a reference to the main project into the control, because
there is no DLL.

So how shall I go about this? I suppose I could just pass the main MDI
parent form as an argument to the constructor of the control, but that
seems kinda hacky... there should be an easier, IntelliSense-friendly way
to do it.

Apr 8 '07 #3
I use the following quite often.

In you child form implement this in the class body.

Private WithEvents MyParentForm As Main

In your childs Load method create a reference.

MyParentForm = CType(Me.MdiParent, Main)

This works with Intellisense. If you need access to controls on the
Parent form, make their scope either Friend or Public.

Apr 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Robert Mark Bram | last post by:
Hi All! Is there a way to reference a window by name without doing something like this: open (, 'windowName'); The open method will open a blank window if there is no window with such a name....
2
by: William Wisnieski | last post by:
Hello Everyone, Access 2000 I have a main form with a continuous subform. On the main form I have a text box that references a field on the subform. What I'd like it to do is show the value...
1
by: Richard Hollenbeck | last post by:
I'm building custom menubars for my application--a different one for each form. When I right-click on a menubar and select Customize and click on the toolbars tab, the menubar called "Menu Bar"...
7
by: Dave | last post by:
I have two forms, Form1 and Form2. From Form2, how do I reference the value in a control on Form1? Or perhaps a more specific question: Form1 contains a textbox with the value of 10. This form...
2
by: Ron | last post by:
I need to write a custom textbox control that references an object located in the Global.asax class, but I can't compile the control into a DLL without including the reference to the project DLL...
3
by: MikeY | last post by:
Hi everyone, I'm having problems, or should I say still having problems with trying to pass data from my custom buttons in my custom controls to my main form listview box. Still scratching my...
6
by: Mat | last post by:
Dear all, What I want to do is be able to use a string to refer to a control on a subform. IE: Forms!("Form1!form2!controlA").name or
2
by: Tom | last post by:
I need to be able to reference some images stored in my VB.NET program. Normally, I would load the images into an ImageList control and use them from there (these are going to be icons). However, I...
0
by: colin | last post by:
Hi, I have an IDE style editor based on the WeifenLuo.WinFormsUI.Docking code, wich I must say seems realy good. Im trying to activate drop down menus and such from various special command...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.