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

MDI child forms' close causes errors

I have an MDI parent form frmMain that *should* allow multiple instances
of a child form frmChild. The frmChild operates completely
independently of frmMain (aside from being an MDI child), and the
frmChild close event occurs via a button on frmChild (from within the
code of frmChild). I need to be able to dynamically create multiple
separate instances of frmChild from frmMain.

The problem:

If two (or more) frmChild's are opened, the close event for one affects
the class level variables and fires the event handlers of the combo
box's for all of the others.

Specifically:

frmChild has combo-boxes cboCountry and cboState. cboState is populated
depending upon the selection of cboCounty, from a data-set dsStates.
cboCountry.SelectedIndexChanged has an event handler
(cboCountry_SelectedIndexChanged) that builds cboState from the dsStates
dataset. On form close, dsStates is set to nothing (dsStates =
nothing).

This causes problems because:

The cboCountry_SelectedIndexChanged event handler fires (several times)
for every frmChild open and attempts to reference dsStates, which has
been set to nothing. (Object reference not set to an instance of the
object)

But:
(a) the cboCountry_SelectedIndexChanged should not fire on the the other
forms because they are (or should be) separate forms and
(b) the dsStates is (should be) a class level variable specific to the
one instance of the form it is referenced in (it should be a separate
referenced variable for each frmChild form).

'the <badbadbad> Code...
'********* in fmrMain *********

Private Sub mnuCreateChild_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles mnuCreateChild.Click

Dim objChild As New frmChild()

objChild.MdiParent = Me
objChild.Show()
Me.Refresh()

End Sub

'********* in frmChild *********

'class level variables

dim dsStates as new DataSet()

'form closing method

Private Sub frmChild_Closing(ByVal sender As Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
'some other stuff...
dsStates.Dispose()
dsStates = Nothing
End Sub

'event handler for cboCountry.SelectedIndexChanged

Private Sub cboCountry_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cboCountry.SelectedIndexChanged

If Loading = False Then

dsStates.Tables("States").DefaultView.RowFilter = "Country =
'" & cboCountry.SelectedValue.ToString & "'"

With cboState
.DataSource = dsStates.Tables("States")
.DisplayMember = "State"
.ValueMember = "State"
.SelectedIndex = 0
End With
End If
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #1
0 1414

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

Similar topics

6
by: Bob | last post by:
Declaring a module level form object in multiple froms within a project to show another project form causes a stack overflow and other assorted errors. Can anyone help?
0
by: clu82 | last post by:
I have an MDI app that allows the user to open multiple client address child forms. The user has a child form open that has client id "1001" and the records associated data displayed. If the user...
0
by: sshuangw | last post by:
Hello: I am encountering a very weird issue with MDI child, Overriden WndProc function and hidden form. Basically, the application has two forms, Form1(parent form), Form2(Child form),...
2
by: Guy Babbitt | last post by:
I have an MDI application that starts an instance of a child form at application start. I have an event handler on a combo box checking for the selected value to change. When the select value...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
8
by: Edwinah63 | last post by:
Hi Everyone, in vb6 i was able to execute the following code and it would close the children is the reverse order they were opened eg the last child opened was the first child to close. in...
7
by: Siv | last post by:
Hi, I have an MDI application that uses a generic "ShowPage" routine in a module that is called when I want to display a child form. The basic idea is that in the module I have declared each form...
6
by: romayankin | last post by:
Can someone explain what am I doing wrong? Header: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ class CMyBase { private: CMyBase(const CMyBase& obj); /* Disable copy constuctor */ void...
13
by: Academic | last post by:
I have a MDI form, sometimes child forms and sometimes forms that are neither If I close the app the child forms closing and closed event happens followed by the Mdi form receiving the...
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: 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
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
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,...
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.