473,778 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Access MDI child properties generically

Hello,

I have an MDI app. There are many child forms and they all have several
things in common. They all have a Save button, a public variable
boolNavigate, and they all have a TreeView called treeBrowse.

I have a generic routine to create the TreeView and add it to a form since I
do this on a dozen or so forms. I also would like to add event handlers in
this generic routine. The handler routines perform the same function on
every form, but they need to reference the boolNavigate variable of the
particular calling form. How can I do this without typing the form in a
case with every possible child form?

Here is my code from a librabry module...

Public Sub CreateBrowserTr ee(ByVal frmParent As Form, ByVal treeIn As
TreeView)
'sets up a generic browser tree view attached to the passed in
parent control
Dim splitBrowse As Splitter

'create a splitter
splitBrowse = New Splitter
With splitBrowse
'...set properties
End With
frmParent.Contr ols.Add(splitBr owse)

'create a tree
treeIn = New TreeView
With treeIn
'...set properties
End With
frmParent.Contr ols.Add(treeIn)

'attach event handlers
AddHandler treeIn.BeforeSe lect, AddressOf TreeBrowse_Befo reSelect
'.... more of same type handlers
End Sub

Private Sub TreeBrowse_Befo reSelect(ByVal sender As Object, ByVal e As
System.Windows. Forms.TreeViewC ancelEventArgs)
'dont allow user to leave this node if bollNavigate is false
If (not sender.boolNavi gate) Then
Beep()
e.Cancel = True
End If
End Sub

The part about 'sender.boolNav igate' does not work. How can I access this
property that I know exists for every given form?

Also, I the code for each form's 'Save' button is the same. Is there a way
I can make a generic handler for that and have it apply to all the forms so
I can maintain 1 routine? Currently every form's save routine looks about
like this...

Private Sub cmdSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdSave.Click
If (SaveFormData(b oolAddingNew, me) Then 'SaveFormData is a
generic data saving routine, pass a flag for new and the parent control
(form)
'reload the data
LoadFormData() 'this routine is different on each
form, but the Save handler would call each form's version
FirstNode(treeB rowse)
cmdNew.Enabled = True 'again, each form has a cmdNew
End If
End Sub

Thanks in advance.
May 14 '06 #1
1 2732
CMM
I'm not really sure if I completely understand the problem... but from what
I could surmise, wouldn't having your child forms implement an Interface
solve your problems?

First off, for the love of god, wrap the boolNavigate var into a Property
called "AllowNavig ate" or something. Add a new Interface file:

Interface IMyChildForm
Property AllowNavigate As Boolean
End Interface

Then add "Implements IMyChildForm" to all your forms.

Then you use as so:

If Not DirectCast(Send er, IMyChildForm).A llowNavigate Then
Beep()
e.Cancel = True
End If
--
-C. Moya
www.cmoya.com

"Mark Hoffy" <ma**@here.co m> wrote in message
news:81******** ********@fe04.l ga...
Hello,

I have an MDI app. There are many child forms and they all have several
things in common. They all have a Save button, a public variable
boolNavigate, and they all have a TreeView called treeBrowse.

I have a generic routine to create the TreeView and add it to a form since
I
do this on a dozen or so forms. I also would like to add event handlers
in
this generic routine. The handler routines perform the same function on
every form, but they need to reference the boolNavigate variable of the
particular calling form. How can I do this without typing the form in a
case with every possible child form?

Here is my code from a librabry module...

Public Sub CreateBrowserTr ee(ByVal frmParent As Form, ByVal treeIn As
TreeView)
'sets up a generic browser tree view attached to the passed in
parent control
Dim splitBrowse As Splitter

'create a splitter
splitBrowse = New Splitter
With splitBrowse
'...set properties
End With
frmParent.Contr ols.Add(splitBr owse)

'create a tree
treeIn = New TreeView
With treeIn
'...set properties
End With
frmParent.Contr ols.Add(treeIn)

'attach event handlers
AddHandler treeIn.BeforeSe lect, AddressOf TreeBrowse_Befo reSelect
'.... more of same type handlers
End Sub

Private Sub TreeBrowse_Befo reSelect(ByVal sender As Object, ByVal e As
System.Windows. Forms.TreeViewC ancelEventArgs)
'dont allow user to leave this node if bollNavigate is false
If (not sender.boolNavi gate) Then
Beep()
e.Cancel = True
End If
End Sub

The part about 'sender.boolNav igate' does not work. How can I access this
property that I know exists for every given form?

Also, I the code for each form's 'Save' button is the same. Is there a
way
I can make a generic handler for that and have it apply to all the forms
so
I can maintain 1 routine? Currently every form's save routine looks about
like this...

Private Sub cmdSave_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles cmdSave.Click
If (SaveFormData(b oolAddingNew, me) Then 'SaveFormData is a
generic data saving routine, pass a flag for new and the parent control
(form)
'reload the data
LoadFormData() 'this routine is different on each
form, but the Save handler would call each form's version
FirstNode(treeB rowse)
cmdNew.Enabled = True 'again, each form has a cmdNew
End If
End Sub

Thanks in advance.

May 16 '06 #2

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

Similar topics

6
10299
by: William Gill | last post by:
I am trying to get & set the properties of a widget's parent widget. What I have works, but seems like a long way around the block. First I get the widget name using w.winfo_parent(), then i convert the name to a reference using nametowidget(). self.nametowidget(event.widget.winfo_parent()).hasChanged= True It works, but I can't help but think I'm missing a more direct route. Am I? Bill
3
2290
by: Adonis Walmsley-McCarthy | last post by:
Hello all, I tried that solution detailed below. However, I get the error "run-time error 13. Type mismatch". The offending line is: Set prop = db.CreateProperty("AllowByPassKey", dbBoolean, False) Do you have any ideas?
0
1299
by: Frank_00001 | last post by:
I'm trying to use Active Directory to get a list of users that are in the same directory as the logon user. I'm trying to do this as a Web App written in C# using Windows Security and Impersonation. When running from the local host I have no problem; but when I try the same thing remotely I get the error "System.Runtime.InteropServices.COMException" on the second hit on Active Directory, the first hit works fine. I used to get the same...
3
1616
by: cbrown | last post by:
I have two forms Main & Child. Main has several readonly properties that I would like to access from the child form. How do I reference the MDI-Parent form MAIN and use those properties.
2
6256
by: Frav | last post by:
The Reps team have been experiencing that Access 2002 unexpectedly quits while working and also lots of Corruption Failures and "Record lock can not update" messages since the upgrade from Windows 2000 and Access 200 to Windows XP and Access 2002 (XP) was done. Now, they are working and at anytime in anywhere of the application access unexpectedly quits with no error messages and the info that was being entered
11
2863
by: manstey | last post by:
Hi, I am having trouble designing my classes. I have two classes. The first one wraps around an old-style class called oref Class CacheClass(object): def __init__(self, obj):
3
1895
by: rick | last post by:
I have a situation where I want to write an extensible class that is capable of saving / restoring properties of classes derived from it. A simplified example is explained as follows;- class A { private $Save ; public function Push() {
1
2254
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm sorry for such a basic question, but here it is: I'm creating a VS2005 C# forms application. In the parent form I have a button that opens a child form. In the code for the parent form I have some public objects and some public methods. How can the child code access those objects and methods? I know that the child has access to the parent properties by using this.Parent, but the only members I see in the parent are the...
0
1079
by: Gurur | last post by:
I want to access the properties of a child form of an application from another application. Properties means I want to perform some action on the visibility of the child form. I have the class name of the main form and its child form. I have the handle of both the parent and child form(using FindWindow).
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10298
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10069
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8957
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7475
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5500
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4033
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2865
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.