473,609 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing public property on multiple instances of open forms

I'm trying to get my feet wet in VB2005 (our new standard at work
after officially stopping new development in VB6 about a month ago).
I'm working with a simple sql 2005 table of 50 entries, one for each
state. Each entry contains Name, postal abbreviation, etc. Just simple
stuff to understand the mechanisms, syntax, etc.

I'm now to the point where I've got a Master MDI form that opens one
or more types of forms, I'm able to edit/save the data and even return
a "Fail" if another user has altered the record by checking the
rowversion/timestamp field.

My current task is trying to poll all the open forms to check a
property unique to that type of form so I can exclude it from the new
open list.

My frmState2 has a public property of .Key which consists of the two-
letter USPS state code; AL, AK, etc. When a new instance of frmState2
is created, I set frmState2.Key to the two letter code and when the
new instance of the form loads, it gets the Me.Key property and is
able to take it from there.

Now, in the frmOpen's routine to fill the Listbox of state names, I'd
like to tack on a WHERE clause to the SQL statement to exlude the
states already open. (The first time through all 50 states show up,
the next time frmOpen is invoked and fills its listbox, it should only
present 49 states, etc.)

To do this I should (be able to) ripple through the open forms and
compile a list of state codes. My problem is accessing the .Key
property.

I'm currently trying:
For Each f As Form In My.Application. OpenForms
If f.Name = "frmState2" Then
MsgBox(f.Key) 'Just to check what I'm referencing
for right now.
End If
Next
I put in the qualifier checking the f.Name since not every type of
form has a .Key property. However, the compiler won't even let me run
it because "'Key' is not a member of 'System.Windows .Forms.Form'".

Multiple instances of frmState2 are not the only form(s) open, I'll
have the mastermdi and frmOpen as well, so not all the forms will have
a .Key property.

I could do this in VB6 because of the "If f.Name" qualifier. I'm going
to need this "type of thing" later to execute each instance's save
routine in case the user closes the application without saving to save
all the data.

There's got to be a way to reference all the instances of this
property!

-Scott
Mar 24 '08 #1
4 2682
<no************ **@hotmail.coms chrieb
I'm currently trying:
For Each f As Form In My.Application. OpenForms
If f.Name = "frmState2" Then
MsgBox(f.Key) 'Just to check what I'm
referencing for right now.
End If
Next
For Each f As Form In Me.MdiChildren
if typeof f is frmState2 Then
MsgBox(directca st(f, frmState2).Key)
End If
Next
Armin
Mar 24 '08 #2
On Mar 24, 12:13*pm, "Armin Zingler" <az.nos...@free net.dewrote:
<nottarealaddr. ..@hotmail.coms chrieb
I'm currently trying:
* * * * * *For Each f As Form In My.Application. OpenForms
* * * * * * * *If f.Name = "frmState2" Then
* * * * * * * * * *MsgBox(f.Key) *'Just to check what I'm
referencing for right now.
* * * * * * * *End If
* * * * * *Next

For Each f As Form In Me.MdiChildren
* * if typeof f is frmState2 Then
* * * * MsgBox(directca st(f, frmState2).Key)
* * End If
Next

Armin
Thank you!
Mar 24 '08 #3
On Mar 24, 12:33 pm, nottarealaddr.. .@hotmail.com wrote:
I'm trying to get my feet wet in VB2005 (our new standard at work
after officially stopping new development in VB6 about a month ago).
I'm working with a simple sql 2005 table of 50 entries, one for each
state. Each entry contains Name, postal abbreviation, etc. Just simple
stuff to understand the mechanisms, syntax, etc.

I'm now to the point where I've got a Master MDI form that opens one
or more types of forms, I'm able to edit/save the data and even return
a "Fail" if another user has altered the record by checking the
rowversion/timestamp field.

My current task is trying to poll all the open forms to check a
property unique to that type of form so I can exclude it from the new
open list.

My frmState2 has a public property of .Key which consists of the two-
letter USPS state code; AL, AK, etc. When a new instance of frmState2
is created, I set frmState2.Key to the two letter code and when the
new instance of the form loads, it gets the Me.Key property and is
able to take it from there.

Now, in the frmOpen's routine to fill the Listbox of state names, I'd
like to tack on a WHERE clause to the SQL statement to exlude the
states already open. (The first time through all 50 states show up,
the next time frmOpen is invoked and fills its listbox, it should only
present 49 states, etc.)

To do this I should (be able to) ripple through the open forms and
compile a list of state codes. My problem is accessing the .Key
property.

I'm currently trying:
For Each f As Form In My.Application. OpenForms
If f.Name = "frmState2" Then
MsgBox(f.Key) 'Just to check what I'm referencing
for right now.
End If
Next
I put in the qualifier checking the f.Name since not every type of
form has a .Key property. However, the compiler won't even let me run
it because "'Key' is not a member of 'System.Windows .Forms.Form'".

Multiple instances of frmState2 are not the only form(s) open, I'll
have the mastermdi and frmOpen as well, so not all the forms will have
a .Key property.

I could do this in VB6 because of the "If f.Name" qualifier. I'm going
to need this "type of thing" later to execute each instance's save
routine in case the user closes the application without saving to save
all the data.

There's got to be a way to reference all the instances of this
property!

-Scott
While Armin has shown you how to loop through the mdichildren and
inspect their types, I would prefer to not do this in the application.
Another option is to fire off an event in the mdi parent that the
various mdi children would subscribe too. Basically, the parent would
send out a "save now" message and any children who hear the message
would execute their save routines.

The main reason I like this pattern is that it enables the parent to
not care in the least what, if any, children it has. The saving is
handled by the children and the parent couldn't care less. To me it is
a much cleaner solution as it has much less coupling between the
different forms. It generally requires more work to initially set up,
but can save time down the road, say if you go from having one type of
form that needs saved to 5 different forms that need saved. Each would
just have to subscribe to the parent's "save now" event and handle
their save routines however they please.

Thanks,

Seth Rowe [MVP]
Mar 24 '08 #4
Seth,

Thanks for this information. I'll definitely look into it. I'm just
making the transition from VB6 to VB2005 and my first priority is "it
works". My second would be "it works better".

Having the children subscribe to the parent's event is going to be a
worthwhile to know because I can see it coming in handy in so many
ways--it's always good to know multiple ways of doing things.

Thanks,
-Scott

Mar 25 '08 #5

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

Similar topics

12
3215
by: (Pete Cresswell) | last post by:
I know I can open many instances of a given form, but I've never done it. Now I'm analyzing an application where that seems like just the ticket: Many investment funds, *lots* of data points for each fund, and a desire by the users to see several funds presented side-by-side. Is opening, say, five instances of the same form real-world-doable? -- PeteCresswell
1
1596
by: Jason Bell | last post by:
Every example of properties I've seen have used simple types such as integers and strings. Here's the scenario I'm trying to work out (3D graphics programming): I have a class called Matrix16f, containing 16 floats that define the matrix, which in turn defines an object's position and orientation in 3D space. As well I want it to have a "position" property, which is a 3D vector that sets the Position values of the matrix.
1
6145
by: Sam Berry | last post by:
I am in need of some guidance on asscessing the same data from multiple forms. I tried using a collection, but everytime that I try to access the collection, I have to use the new word. colStuff ns = new colStuff When I try to access the items in the collection, they are not there (ie the values from a different form). Could somebody point me in the right direction to get this working? Thanks,
3
2787
by: Vivek Sharma | last post by:
Hi, I have created a dropdownlist as a web user control. I am using its multiple instances on the webpage. How do I access the selectedValue of each instance? All the instances have different IDs. Thanks Vivek
5
1941
by: RSH | last post by:
I havent been able to set a property from another class with out getting some sort of error. Can someone please tell me what I'm doing wrong here? Public Class Form1
4
3282
by: GGerard | last post by:
Hello I have a program where the user can open as many instances of a form as the user wants. The only limit to how many instances can be opened is determined by the limit of the computer itself (the amount of RAM - I think). When enough instances of this form are opened and the limit of the computer is reached
0
12069
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
6
2640
by: Bob Alston | last post by:
Looking for someone with experience building apps with multiple instances of forms open. I am building an app for a nonprofit organizations case workers. They provide services to the elderly. so far I have built a traditional app, switchboard, forms, etc. Part of this app is to automate the forms they previously prepared manually. After the app was built and works just fine, I find out there are several case managers using MS word...
12
4801
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
0
8127
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
8067
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8567
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...
0
8527
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8215
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
8398
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...
1
6053
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
4076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.