|
-
May 8th, 2014, 08:25 AM
#1
Thread Starter
Addicted Member
[RESOLVED] datagridview and events - code jumps out of sub on event and never comes back
Hi,
I have a dgv which I layout on a "form load" event and my code wasn't adding the row headers properly.
When I stepped through the code it got to the line where it added 8 rows (the dgv is not bound to a datasource) and then jumped out to another event (dgvHD_CD_CellEnter) and when that event finished, the code jumped back to the button on the previous form that had opened this form in the 1st place and missed out the rest of the code on the form load which set up the row headers.
After a lot of fannying about, I set the dgv.visible property to false before I added the rows and set it back again once I set up the row headers and this stopped the code jumping out of the "form load" code. I guess the dgvHD_CD_CellEnter event doesn't fire if the control isn't visible.
Is this behaviour normal?
My Code on the form load:
Code:
dgvHD_CD.Visible = False ' Now added to fix problem
dgvHD_CD.Rows.Add(8)
For byteRow_Index = 0 To 7
dgvHD_CD.Rows(byteRow_Index).HeaderCell.Value = strWell_Plates_Rows.ToString.Substring(byteRow_Index, 1)
dgvHD_CD.Rows(byteRow_Index).Height = Math.Floor((dgvHD_CD.Height - dgvHD_CD.ColumnHeadersHeight) / 8)
Next
dgvHD_CD.SendToBack()
dgvHD_CD.Visible = True
and
Code:
Private Sub dgvHD_CD_CellEnter(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvHD_CD.CellEnter
If boolLeft_Cell Then
dt96_Description.Rows(byte96Cell_Row_Index).Item(byte96Cell_Column_Index) = txt96_Description.Text
boolLeft_Cell = False
End If
txt96_Description.Text = ""
If Len(dt96_Description.Rows(e.RowIndex).Item(e.ColumnIndex) & "") > 0 Then
txt96_Description.Text = dt96_Description.Rows(e.RowIndex).Item(e.ColumnIndex)
End If
End Sub
Thanks
Kristian
-
May 8th, 2014, 09:32 AM
#2
Re: datagridview and events - code jumps out of sub on event and never comes back
Try removing or commenting out those lines that change the grid visibility and wrap the contents of the Load event handler in an exception handler, i.e. Try...Catch block. Most likely an exception is being thrown that you're not seeing because they get swallowed in a Load event handler on 64-bit systems. If that is the case, once you know what it is, you can find a real solution.
-
May 9th, 2014, 02:47 AM
#3
Thread Starter
Addicted Member
Re: datagridview and events - code jumps out of sub on event and never comes back
 Originally Posted by jmcilhinney
Try removing or commenting out those lines that change the grid visibility and wrap the contents of the Load event handler in an exception handler, i.e. Try...Catch block. Most likely an exception is being thrown that you're not seeing because they get swallowed in a Load event handler on 64-bit systems. If that is the case, once you know what it is, you can find a real solution.
I'll give it a go and let you know what happens.
Thanks
Kristian
-
May 12th, 2014, 03:38 AM
#4
Thread Starter
Addicted Member
Re: datagridview and events - code jumps out of sub on event and never comes back
 Originally Posted by jmcilhinney
Try removing or commenting out those lines that change the grid visibility and wrap the contents of the Load event handler in an exception handler, i.e. Try...Catch block. Most likely an exception is being thrown that you're not seeing because they get swallowed in a Load event handler on 64-bit systems. If that is the case, once you know what it is, you can find a real solution.
Hi again,
Remove visisble = false line and put a 'try...catch' in and got a "Object reference not set to an instance of an object." error.
It seems that as I try to add some rows, this triggers an event that I wasn't expecting which caused a problem, but didn't cause an error at the time, it just jump out of that section of code.
Had same symptoms this morning when trying to change the file format of an Excel spreadsheet - no events this time, just a line of code which Visual Studio didn't like and so it just skipped the rest of the procedure.
Thanks twice for your advice.
Kristian
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|