[RESOLVED] DataGridView WinForms
I have a WinForms app that has a DGV that's bound to a BindingSource and when the user clicks on the new row line @ the bottom I would like it to fill in two columns values automatically but I'm not sure which event is fired when that row is switches to user editing mode.
Re: DataGridView WinForms
try this:
vb Code:
Private Sub dgv1_CellMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgv1.CellMouseDown
If e.RowIndex = dgv1.NewRowIndex Then
dgv1(0, e.RowIndex).Value = "test1"
dgv1(1, e.RowIndex).Value = "test2"
End If
End Sub
Re: [RESOLVED] DataGridView WinForms
Thanks, I changed it from MouseDown to MouseUp and all's working right.
Re: [RESOLVED] DataGridView WinForms
why? MouseDown worked ok for me
Re: [RESOLVED] DataGridView WinForms
Because I would have to click twice to get it to show when I was using the MouseDown event. In the Click event internally it sets the cells when it's moved to the new index, so by using the MouseUp event my data is added and it sticks on the first click.
Re: [RESOLVED] DataGridView WinForms
This should have nothing at all to do with the grid. Does it not seem like a hack handling mouse events of a grid to populate fields in new bound items?
You should be handling the AddingNew event of your BindingSource. There you can either create an populate a new item or else set the fields of the new DataRowView, depending on what you're bound to.
The whole point of using a BindingSource is so that you can do data-binding related things like this easily. If you don't use the BindingSource for this sort of thing then using it at all is pointless.