Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem closing form

Status
Not open for further replies.

kimprogrammer

Programmer
Sep 15, 2008
160
CA
Hello
I have a few forms created and have set up a menu for them - when I debug this my menu comes up I can select my form and it opens but when I close the form it gives me an error message on one of the dropdown box's .selectedindexchanged.

I havn't entered anything and it gives me an error NullReference not set to an instance of an object on a tableadapter where I convert the parameter to string.

Could someone help me with what I'm missing.

Thanks
 
Can you post the code you have to create and display the form, the code in the .SelectedIndexChanged event and any code in the closing type events of the form (Disposed/FormClosed/FormClosing)?
 
Here is the code for selectedindexchange - I just recently put the catch try around it. I have no code with a closing method - I didn't think I needed one.

Also I created file with a screen print but I'm not sure how to put the attachment in - do I need to subscripe to the file storage to do this?
------------------------------------
'
'selects division
'
Private Sub cboDivision_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboDivision.SelectedIndexChanged

Dim drv As DataRowView = CType(cboDivision.SelectedItem, DataRowView)

Try
PClass = Trim(drv.Item("PClass").ToString)
'TODO: This line of code loads data into the 'HYLTDDataSet.CPY10100' table. You can move, or remove it, as needed.
Me.CPY10100TableAdapter.FillByDivision(Me.HYLTDDataSet.CPY10100, Convert.ToString(drv.Item("PClass")))
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

lblTotEmpCount.Text = (Me.HYLTDDataSet.CPY10100.Rows.Count).ToString
End Sub
-------------------------------------
 
PClass = Trim(drv.Item("PClass").ToString)

I have my other screen that throws the same exception.
 
Well, your drv.Item("PClass") is set to nothing. For a quick fix, you can do something like:

Code:
If Not drv.Item("PClass") Is Nothing Then
  PClass = Trim(drv.Item("PClass").ToString)
Else
  'Set PClass to something else, or exit routine, etc.
End If

However, I'm still not sure about the root of your problem, as in why it's occurring when you close the form.
 

Could setting the selectedindex when I load the form resolve this issue as well?
 
I tried setting the selected index to 0 and 1 and still got the same error at the same point.

I put in your sugestion and I get the same error pointing to
If Not drv.Item("PClass") Is Nothing Then
of the code you supplied.
 
Try

If Not drv Is Nothing.


That's what I should have posted the first time. You want to check that the DataRowView object is set to something, not the column in this case.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top