Interesting that not a lot of people are using the datagridview object yet.
Anyway, here is what I do. In my example (from an app I am currently working
on) I add data to the new row to the datagridview. The trick is to add the
row to the underlying dataTable which is the datasource of the datagridview:
Private Sub dgrModSubDetail_CellEndEdit(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles
dgrModSubDetail.CellEndEdit
Dim dr As DataRow
If e.RowIndex > dsWeb.Tables("modSubDetail").Rows.Count - 1 Then
dr = dsWeb.Tables("modSubDetail").NewRow
dsWeb.Tables("modSubDetail").Rows.Add(dr)
dsWeb.Tables("modSubDetail").AcceptChanges()
End If
End Sub
e is the datagridview cell event arg for the CellEndEdit event of the
datagridview. I have observed that the CellEndEdit event is the last event
to fire when you leave a datagridview. e returns the row index (and also
column index). If the row index is greater than the number of rows in the
underlying datatable, I add a new datarow to the underlying datatable. You
can edit the datarow directly from/through the datagridview. This is very
convenient because you don't have to do the dr.Item(0) = ... like in vb2003.
Once you get the hang of the datagridview - it is real nice. Note: I am open
to suggestions here if my method is on the kludgy side.
Rich
"bo*@datasync.com" wrote:
Can anyone tell me the best way to update a dataset while it is being
edited/viewed in the DataGridView control? Is this something that
should be inserted into one of the grid's events? or should you update
after closing the grid/form, etc.?
Also, can you tell me the best book to buy that fully explains the
DataGridView control?
Thanks.