Cannot access disposed object named 'DataGridTextBox'

  • Thread starter Thread starter Burak
  • Start date Start date
B

Burak

Hello,

I am working on a windows forms app with a datagrid. In my mouse down
event, I am calling Me.Close() and am running into the following error

Cannot access disposed object named "DataGridTextBox"
Object name: "DataGridTextBox"

Private Sub dtgResults_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles dtgResults.MouseDown
Dim str As String = ""

Dim hti As DataGrid.HitTestInfo

hti = dtgResults.HitTest(e.X, e.Y)

Try

If hti.Type = DataGrid.HitTestType.Cell Or hti.Type =
DataGrid.HitTestType.RowHeader Then

str += dtgResults(hti.Row, 0).ToString()

global_vars.PROVIDS = str

End If

Catch ex As Exception

MsgBox(ex.Message)

End Try

If str <> "" Then

Me.Close()

End If

End Sub

In a previous thread about the same problem,
See if taking out the Me.Close makes the problem go
away. If it does,you'll hav to arrange a different way to
close the form. One idea is to start a timer with a very
short delay and close the form when it goes off.

I put in a timer into the the code as below. I haven't used a timer
before so I think I did it wrong because this did not work either.

If str <> "" Then
Timer1.Interval = 1000

Timer1.Start()

Timer1.Stop()

Me.Close()

End If

What am I doing wrong?

Burak
 
I had this error once - try adding this before you Me.Clos
Dim dgcs As DataGridColumnStyle = dtgResults.TableStyles(0).GridColumnStyles(dtgResults.CurrentCell.ColumnNumber
dtgResults.EndEdit(dgcs, dtgResults.CurrentCell.RowNumber, True
 
Hello,

Thanks for your reply.

I put in the code you wrote
Dim dgcs As DataGridColumnStyle = dtgResults.TableStyles(0).GridColumnStyles(dtgResults.CurrentCell.Column
Number)
dtgResults.EndEdit(dgcs, dtgResults.CurrentCell.RowNumber, True)

and still got the same error message.

Any other ideas?

Burak
 
Back
Top