running32
asked on
Cannot access a disposed object named "TreeView".
I am getting the error when I try to close the form. Cannot access a disposed object named "TreeView".
Not sure what why.
Thanks
Not sure what why.
Thanks
Private Sub frmMHContactLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connection1.Open()
Me.Size = New Size((Me.MdiParent.Size.Width - 17), Me.MdiParent.Size.Height)
Dim daSections As New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT convert(varchar(10),dbo.tblMHCIntake.dtmIntake,101) as intakedate,dtmintake, DATENAME(dw, dbo.tblMHCIntake.dtmIntake) AS dayname FROM dbo.tblMHCIntake where dtmintake > '01/01/2008'ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)
Dim daContent As New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT dbo.tblPatient.strLName + ', ' + dbo.tblPatient.strFName AS name, convert(varchar(10),dbo.tblMHCIntake.dtmIntake,101) as intakedate,dbo.tblMHCIntake.dtmIntake, dbo.tblMHCIntake.strStaff, convert(varchar(10),dbo.tblPatient.dtmDOB,101) as dtmdob, dbo.tblPatient.strPatientId, dbo.tblMHCIntakeDetail.lngIntakeId FROM dbo.tblMHCIntake INNER JOIN dbo.tblMHCIntakeDetail ON dbo.tblMHCIntake.lngIntakeId = dbo.tblMHCIntakeDetail.lngIntakeId right JOIN dbo.tblPatient ON dbo.tblMHCIntake.lngPatientId = dbo.tblPatient.lngPatientId where dtmintake > '1/1/2008'ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)
daSections.Fill(objDS, "dtSections")
daContent.Fill(objDS, "dtContent")
objDS.Relations.Add("SectionToContent", _
objDS.Tables("dtSections").Columns("dtmIntake"), _
objDS.Tables("dtContent").Columns("dtmIntake"))
For Each rowSupp In objDS.Tables("dtSections").Rows
nodeSupp = New TreeNode
nodeSupp.Text = rowSupp("dtmIntake")
TreeView1.Nodes.Add(nodeSupp)
For Each rowProd In rowSupp.GetChildRows("SectionToContent")
nodeProd = New TreeNode
nodeProd.Text = rowProd("intakedate") & " - " & rowProd("strStaff") & " - " & rowProd("name") & " - " & rowProd("dtmdob") & " - " & rowProd("strPatientid")
'need to databind rowProd ("lngIntakeId")
nodeProd.Tag = rowProd("lngIntakeID")
nodeSupp.Nodes.Add(nodeProd)
Next
Next
'clean up
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
MHIntakeID = e.Node.Tag
'subclose()
If MHIntakeID <> "" Then
Dim child As New frmMHClientContact
child.MdiParent = Me.MdiParent
child.Show()
Me.Close()
End If
End Sub
What is the clean up? Are you calling any other code here that might be disposing of the TreeView? Is there any code in the form_closing or form_closed events?
ASKER
No close events. I commented out the client up so I am disposing of any thing. Thanks
This exception occur because the program is trying to access TreeView1 after the form has been disposed.
Try this:
Try this:
Private Sub frmMHContactLog_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Connection1.Open()
Me.Size = New Size((Me.MdiParent.Size.Width - 17), Me.MdiParent.Size.Height)
Dim daSections As New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT convert(varchar(10),dbo.tblMHCIntake.dtmIntake,101) as intakedate,dtmintake, DATENAME(dw, dbo.tblMHCIntake.dtmIntake) AS dayname FROM dbo.tblMHCIntake where dtmintake > '01/01/2008'ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)
Dim daContent As New SqlDataAdapter("SELECT DISTINCT TOP 100 PERCENT dbo.tblPatient.strLName + ', ' + dbo.tblPatient.strFName AS name, convert(varchar(10),dbo.tblMHCIntake.dtmIntake,101) as intakedate,dbo.tblMHCIntake.dtmIntake, dbo.tblMHCIntake.strStaff, convert(varchar(10),dbo.tblPatient.dtmDOB,101) as dtmdob, dbo.tblPatient.strPatientId, dbo.tblMHCIntakeDetail.lngIntakeId FROM dbo.tblMHCIntake INNER JOIN dbo.tblMHCIntakeDetail ON dbo.tblMHCIntake.lngIntakeId = dbo.tblMHCIntakeDetail.lngIntakeId right JOIN dbo.tblPatient ON dbo.tblMHCIntake.lngPatientId = dbo.tblPatient.lngPatientId where dtmintake > '1/1/2008'ORDER BY dbo.tblMHCIntake.dtmIntake DESC", Connection1)
daSections.Fill(objDS, "dtSections")
daContent.Fill(objDS, "dtContent")
objDS.Relations.Add("SectionToContent", _
objDS.Tables("dtSections").Columns("dtmIntake"), _
objDS.Tables("dtContent").Columns("dtmIntake"))
For Each rowSupp In objDS.Tables("dtSections").Rows
nodeSupp = New TreeNode
nodeSupp.Text = rowSupp("dtmIntake")
TreeView1.Nodes.Add(nodeSupp)
For Each rowProd In rowSupp.GetChildRows("SectionToContent")
nodeProd = New TreeNode
nodeProd.Text = rowProd("intakedate") & " - " & rowProd("strStaff") & " - " & rowProd("name") & " - " & rowProd("dtmdob") & " - " & rowProd("strPatientid")
'need to databind rowProd ("lngIntakeId")
nodeProd.Tag = rowProd("lngIntakeID")
nodeSupp.Nodes.Add(nodeProd)
Next
Next
'clean up
End Sub
Private Sub TreeView1_AfterSelect(ByVal sender As Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles TreeView1.AfterSelect
If Me.IsDisposed = False Then
MHIntakeID = e.Node.Tag
'subclose()
If MHIntakeID <> "" Then
Dim child As New frmMHClientContact
child.MdiParent = Me.MdiParent
child.Show()
Me.Close()
End If
End If
End Sub
ASKER
still got the same error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you