datagridview event conflict when adding data

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
159
Programming Experience
1-3
I have a datagridview with a hidden column where when I add a new row I update the hidden column with code...

I want to update the hidden column automatically when I add a new row but this wont work as when the form is being drawn the event's kick off causing havoc...

e.g
Private Sub BindingNavigatorAddNewItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem1.Click
Me.ChildRecChanged = True
ToolStripButton1.BackColor = Color.GreenYellow
Me.DataGridView1.CurrentRow.Cells("PersonnelNo").Value = StaffID
End Sub

This fails because row has not yet been added and I cant see any other event that doesn't kick off until after form shown.

Any advice appreciated....
 

divjoy

Well-known member
Joined
Aug 25, 2013
Messages
159
Programming Experience
1-3
I developed a work around where I loop over the datagrid rowa, inserting the StaffID value into every empty column.

I stored it in the a button click event on the save button!

I thought this was better than what was being recommended online, to use a boolean flag datagrid added new row event, to stop the event code executing until the form was fully loaded...

Any other possible ideas?
 
Top Bottom