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

Multiple forms hold different data

Hiya,

New to VB.NET so this is probably a fairly easy solution(?!?!)

I have an application which currently uses singleton forms. Great -
everything worked fine except the users now want the ability to open
mulitple records.

So scenerio is I have a main parent form which has a text box for
customer number. After entering the number a new form appears which
contains the customer information. Now what I want is they can enter
another customer number which then opens another customer form with
the new customer info. This I have achieved. The problem I have is I
use classes to hold the cust info since they can go to sub forms from
the main form (saves passing params all over the place).

So ParentForm calls Form1 and then ParentForm calls Form1 again (so
both Form1's are displayed but with different customer info). When I
get the focus of one of the customer forms my class remembers the last
customer form open.

How do I when getting the focus for the whichever customer form also
gets the correct customer form class data.

I would have thought that creating a new customer class when each new
form is opened would be for that form only but this seems not to be
the case.

FYI - Visual Studio 2005 VB.NET

Thanks in advance
Bazza

Jun 19 '07 #1
3 2144
On Jun 19, 9:13 am, Bazza <barrysmith1...@googlemail.comwrote:
Hiya,

New to VB.NET so this is probably a fairly easy solution(?!?!)

I have an application which currently uses singleton forms. Great -
everything worked fine except the users now want the ability to open
mulitple records.

So scenerio is I have a main parent form which has a text box for
customer number. After entering the number a new form appears which
contains the customer information. Now what I want is they can enter
another customer number which then opens another customer form with
the new customer info. This I have achieved. The problem I have is I
use classes to hold the cust info since they can go to sub forms from
the main form (saves passing params all over the place).

So ParentForm calls Form1 and then ParentForm calls Form1 again (so
both Form1's are displayed but with different customer info). When I
get the focus of one of the customer forms my class remembers the last
customer form open.

How do I when getting the focus for the whichever customer form also
gets the correct customer form class data.

I would have thought that creating a new customer class when each new
form is opened would be for that form only but this seems not to be
the case.
I accomplished the same task by having a property in the sub (child)
form that is an object instance of the class so each sub form has it's
own instance of the base class.

Jun 19 '07 #2
>
I accomplished the same task by having a property in the sub (child)
form that is an object instance of the class so each sub form has it's
own instance of the base class.- Hide quoted text -

- Show quoted text -
Thanks for replying. Not totally sure whats been said here (like I
said still a newbie).

I have changed my code to the following (code trimmed for ease)

Parent Code :

......
If RecFound = True Then
clsCurrentRecord.company_id = tb_company_id.text
clsForms.frmcompany = New Company
clsForms.frmcompany.MdiParent = Me
clsForms.frmcompany.Show()
clsForms.frmcompany.Focus()
End If
......
frmcompany :

Public Class Company
Inherits System.Windows.Forms.Form

Private CompRec As New clsLocalCompanyRecord
Private Class clsLocalCompanyRecord
Shared m_company_id As String
Property company_id() As String
Get
Return m_company_id
End Get
Set(ByVal Value As String)
m_company_id = Value
End Set
End Property

... more properties ....

End Class
Private Sub Company_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CompRec = New clsLocalCompanyRecord
CompRec.company_id = clsCurrentRecord.company_id
LoadCompanyDetails()
Me.Text = CompRec.company_name & " (" & CompRec.company_id &
")"
End Sub
Everytime I create a new instance of the form the class is set to the
record loaded. When I go back and get the focus of the first form
opened the class data contains the data from the last form opened.

Have I missed something completly obvious like going back to
COBOL? ;-)

If you could expand on your method in code I would be very grateful.
Thanks in advance
Bazza
Jun 19 '07 #3
On Jun 19, 11:30 am, Bazza <barrysmith1...@googlemail.comwrote:
I accomplished the same task by having a property in the sub (child)
form that is an object instance of the class so each sub form has it's
own instance of the base class.- Hide quoted text -
- Show quoted text -

Thanks for replying. Not totally sure whats been said here (like I
said still a newbie).

I have changed my code to the following (code trimmed for ease)

Parent Code :

.....
If RecFound = True Then
clsCurrentRecord.company_id = tb_company_id.text
clsForms.frmcompany = New Company
clsForms.frmcompany.MdiParent = Me
clsForms.frmcompany.Show()
clsForms.frmcompany.Focus()
End If
.....

frmcompany :

Public Class Company
Inherits System.Windows.Forms.Form

Private CompRec As New clsLocalCompanyRecord
Private Class clsLocalCompanyRecord
Shared m_company_id As String
Property company_id() As String
Get
Return m_company_id
End Get
Set(ByVal Value As String)
m_company_id = Value
End Set
End Property

... more properties ....

End Class

Private Sub Company_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
CompRec = New clsLocalCompanyRecord
CompRec.company_id = clsCurrentRecord.company_id
LoadCompanyDetails()
Me.Text = CompRec.company_name & " (" & CompRec.company_id &
")"
End Sub

Everytime I create a new instance of the form the class is set to the
record loaded. When I go back and get the focus of the first form
opened the class data contains the data from the last form opened.

Have I missed something completly obvious like going back to
COBOL? ;-)

If you could expand on your method in code I would be very grateful.
Thanks in advance
Bazza
I think you need to load the company_id property before the form is
shown.

Jun 19 '07 #4

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

Similar topics

6
by: Otie | last post by:
I have a project with a main form and a second form with a grid on it. Neither form is an MDI, thus neither form is a child - they are two independent forms. The CALCULATE button on the main form...
11
by: dskillingstad | last post by:
I've been struggling with this problem for some time and have tried multiple solutions with no luck. Let me start with, I'm a novice at Access and I'm not looking for someones help to design my...
0
by: Anonieko Ramos | last post by:
ASP.NET Forms Authentication Best Practices Dr. Dobb's Journal February 2004 Protecting user information is critical By Douglas Reilly Douglas is the author of Designing Microsoft ASP.NET...
7
by: jsale | last post by:
I have made an ASP.NET web application that connects to SQL Server, reading and writing data using classes. I was recommended to use session objects to store the data per user, because each user...
7
by: Jeff | last post by:
I plan to write a Windows Forms MDI application for a medical office. Users must be able to select a patient and view related information on multiple forms; with1-4 forms opened at the same time...
6
by: thomson | last post by:
Hi All, i do hae a solution in which i do have mulitple projects including Web Projects,, Depending on the functionality it gets redirected to different web projects and it is working fine, ...
3
by: imrantbd | last post by:
This is my first problem.Please help me. I have the following code: <head> <script language="JavaScript"> function addSrcToDestList() { destList1 = window.document.forms.destList; srcList...
5
by: c676228 | last post by:
Hi everyone, my colleagues are thinking about have three insurance plans on one asp page: I simplify the plan as follow: text box:number of people plan1 plan2 plan3
4
by: MoroccoIT | last post by:
Greetings - I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
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...

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.