Update a dataset bound to a grid

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
I have a problem whereby I wish to update a dataset bound to a datagrid without the user having to click on the next row of the grid to initiate an update.
I have the following event code for my grid

Private Sub dgMyDatagrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgMyDatagrid.CurrentCellChanged

AddHandler dsOrders.Tables.Item("Orders").ColumnChanged, New DataColumnChangeEventHandler(AddressOf Order_Changed)

Call UpdateDataSet(dsOrders, "Orders", MyOrderAdapter)

End Sub

I have the handler for the dataset column change as below

Private Sub GableLadder_Changed(ByVal sender As Object, ByVal e As DataColumnChangeEventArgs)

Call UpdateDataSet(dsOrders, "Orders", MyOrderAdapter)

End Sub


Private Sub UpdateDataSet(ByRef Mydataset As DataSet, ByVal strtable As String, ByVal Myadapter As SqlDataAdapter)
Dim objCommandBuilder As New SqlCommandBuilder(Myadapter)

Myadapter.Update(Mydataset, strtable)

End Sub

The Handler is called when a single column is changed but the underlying dataset is only changed when you click on the row above or below in the datagrid.

How can I get the datasource to update to the database without the user having to click on the next row.

Thnx in advance
Geraldine
 
Hi Geraldine,

I think you have more code than needed now, but add this somewhere before
the update

DirectCast(BindingContext(dsOrders.Tables(0)),
CurrencyManager).EndCurrentEdit()

I think that your problems are than gone?

Cor
 
Hi Cor
Thanx a lot, that works a treat, your'e a sta

Geri

----- Cor wrote: ----

Hi Geraldine

I think you have more code than needed now, but add this somewhere befor
the updat

DirectCast(BindingContext(dsOrders.Tables(0))
CurrencyManager).EndCurrentEdit(

I think that your problems are than gone

Co
 
Geraldine Hobley said:
Hi Cor,
Thanx a lot, that works a treat, your'e a star

Geri x

----- Cor wrote: -----

Hi Geraldine,

I think you have more code than needed now, but add this somewhere before
the update

DirectCast(BindingContext(dsOrders.Tables(0)),
CurrencyManager).EndCurrentEdit()

I think that your problems are than gone?

Cor

Can you guys help me as well for my post thread "Please help in
Update---Newbie question ".
 
Back
Top