473,387 Members | 1,925 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,387 software developers and data experts.

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 CreateBrowserTree(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.Controls.Add(splitBrowse)

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

'attach event handlers
AddHandler treeIn.BeforeSelect, AddressOf TreeBrowse_BeforeSelect
'.... more of same type handlers
End Sub

Private Sub TreeBrowse_BeforeSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs)
'dont allow user to leave this node if bollNavigate is false
If (not sender.boolNavigate) Then
Beep()
e.Cancel = True
End If
End Sub

The part about 'sender.boolNavigate' 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
If (SaveFormData(boolAddingNew, 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(treeBrowse)
cmdNew.Enabled = True 'again, each form has a cmdNew
End If
End Sub

Thanks in advance.
May 14 '06 #1
1 2713
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 "AllowNavigate" 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(Sender, IMyChildForm).AllowNavigate Then
Beep()
e.Cancel = True
End If
--
-C. Moya
www.cmoya.com

"Mark Hoffy" <ma**@here.com> wrote in message
news:81****************@fe04.lga...
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 CreateBrowserTree(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.Controls.Add(splitBrowse)

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

'attach event handlers
AddHandler treeIn.BeforeSelect, AddressOf TreeBrowse_BeforeSelect
'.... more of same type handlers
End Sub

Private Sub TreeBrowse_BeforeSelect(ByVal sender As Object, ByVal e As
System.Windows.Forms.TreeViewCancelEventArgs)
'dont allow user to leave this node if bollNavigate is false
If (not sender.boolNavigate) Then
Beep()
e.Cancel = True
End If
End Sub

The part about 'sender.boolNavigate' 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdSave.Click
If (SaveFormData(boolAddingNew, 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(treeBrowse)
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
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...
3
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",...
0
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...
3
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
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...
11
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
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...
1
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.