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. 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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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....
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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....
| |