problem with datagrid and how to update database when cell changes

  • Thread starter Thread starter TM
  • Start date Start date
T

TM

I have a problem with the datagrid where I wanted to detect any changes to
the grid, such as a record being changed, added or deleted. So I used the
currentcellchanged method and used the code
below to update the database. But for some reason, it is detecting and
correctly updating the database on add and remove of records. But is not
writing cell changes back to the database. ANy ideas ?

'this sub will handle if a cell is changed or if a new record is added
Dim dgCell As DataGridCell = grdShoppingList.CurrentCell
Dim strIsle As String = grdShoppingList.Item(dgCell.RowNumber, 0).ToString
Dim strItem As String = grdShoppingList.Item(dgCell.RowNumber, 1).ToString
If strItem.Trim = "0" And strItem.Trim.Length <> 0 Then
'do not add record if it is blank
'write updates to database file and set label to number of records
objShoppingListDA.Update(objShoppingListDataSet, "ShoppingList")
updateShoppingLabel()
End If

ALso, is there any way to force a re-sort of the grid when I add or delete
records so that it is now sorted in the proper order ?

Thanks
 
Hi TM,

A datagrid is what it says a grid for data.

That data is alway in a ilist class (for a datagrid mostly a datatable I
think) often it is filtered by a dataview.

Therefore to see the changes (and I keep it simple by asuming you use a
datatable) you can watch the changes in the datatable. (A datatable can be a
part of a dataset)

I hope this helps a little bit.

Cor
 
Back
Top