Multiple forms hold different data

  • Thread starter Thread starter Bazza
  • Start date Start date
B

Bazza

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
 
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.
 
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
 
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.
 
Back
Top