Combo Box Selected Value changed event Gives Unhandleed exception.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey All,
What we are trying to achieve is, when Selected value changed event is fired
for a combo box, then we are trying to close the current form and display the
new form. The forms are mdi child of a MDI form named as MasterForm.

The code being used to close the current form and open the new form is as
follows:

lForm = new TestForm
lForm.MdiParent = Me.MdiParent
lForm.Show()
Me.Close()

Problem is on Selected value changed event, we get an unhandled exception,
Object reference not set to an instance of Object. I debugged and found that
while closing the current form, its throwing the error.

Can anyone please suggest this behaviour, is it a known issue.

Thanks,

Vinay Kant
 
I don't know how you've declared lForm, but you should declare it as public
in your MDI form, then

CType(Me.MdiParent, MAINMDI).lForm = New TestForm

CType(Me.MdiParent, MAINMDI).lForm.Show()

Me.Close()
 
Altaf,
I used a Dim to declare that, i have event tried declaring it as public,
still the same problem. Code just breaks and takes me to the MDI Parent class
while debugging.
Problem persists. Any other suggestions.

Thanks,
Vinay kant
 
I tried this out myself. Let me post all the code I used and you can
compare.

MDI Declarations, outside any sub:
Public f1 As Form1

Public f2 As Form2


MDI Load event:

f1 = New Form1

f1.MdiParent = Me

f1.Show()

In a button click event in form1,

CType(Me.MdiParent, MAINMDI).f2 = New Form2

CType(Me.MdiParent, MAINMDI).f2.MdiParent = Me.MdiParent

CType(Me.MdiParent, MAINMDI).f2.Show()

Me.Close()


Compare well?
HTH
Altaf
 
Altaf,

It works fine with the Button click event, but doing the same on TextChanged
event of a combo box throws the error.
Can you please try that as well?

Thanks for your support,
Vinay Kant
 
Back
Top