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

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 2667
<no**************@hotmail.comschrieb
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(directcast(f, frmState2).Key)
End If
Next
Armin
Mar 24 '08 #2
On Mar 24, 12:13*pm, "Armin Zingler" <az.nos...@freenet.dewrote:
<nottarealaddr...@hotmail.comschrieb
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(directcast(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
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...
1
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...
1
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...
3
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...
5
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
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...
0
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...
6
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. ...
12
by: Robert Fuchs | last post by:
Hello, This example: public class BaseC { public int x; public void Invoke() {} } public class DerivedC : BaseC
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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,...

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.