Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update dataset from datagrid

Status
Not open for further replies.

Reinout

IS-IT--Management
Feb 22, 2004
48
BE
I have 3 datagrids in 1 page, in parent - child_1 - child_1.1 relation. Now I want to save changes in one datagrid when I move to another. I tried this using :

Me.BindingContext(dataset.Tables("tablename")).EndCurrentEdit()
Call UpdateTable()

This won't work though, he sees no changes in the dataset. When I put a messagebox in front everything's working fine though :s

MsgBox("hier")
Me.BindingContext(dataset.Tables("tablename")).EndCurrentEdit()
Call UpdateTable()

So this one works ! But it's not really my goal to use a textbox everytime I change from one datagrid to another. Anyone has a better idea?
 
Is there another way to simulate a row change?
 
dtgGerechtTypes.EndEdit(Nothing, dtgGerechtTypes.CurrentRowIndex, False)
dtgGerechtTypes.BindingContext(dtgGerechtTypes.DataSource, dtgGerechtTypes.DataMember).EndCurrentEdit()
Call controlesUpdateGerechtTypes()


This works, but I can't enter the cell again, unless I change cells a couple of times :s
 
Problem was solved as soon as I added this code to all datagrids on the page. Don't ask me why, but it works now :)

I'll paste the whole sub for those interested :

Private Sub myDatagrid_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDatagrid.Leave
If controlDatagrid Then
myDatagrid.EndEdit(Nothing, myDatagrid.CurrentRowIndex, False)
myDatagrid.BindingContext(myDatagrid.DataSource, myDatagrid.DataMember).EndCurrentEdit()
Call UpdateDatabase()
controlDatagrid = False
Else
controlDatagrid = True
End If
End Sub

I insert a boolean because he tends to go through the sub twice, first trying to leave the datagrid, but the update sub keeps the focus on the datagrid, the second time the event is called I don't want to look for possible changes, so I added the "controlDatagrid = false" to the first part, I put it back on true in case I enter and leave the datagrid again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top