
Add row to datatable from datagrid without leaving current row with cursor
How do I add a row to a datatable from a datagrid without clicking somewhere
else in the grid?
I use the following code to detect if something has changed in the
datatable:
myDataTable.GetChanges(DataRowState.Modified)
myDataTable.GetChanges(DataRowState.Deleted)
If I modify a cell without tabbing to the next or clicking somwhere else
before I hit the save button the row beneath will result in 'Nothing'
myDataTable.GetChanges(DataRowState.Modified)
I solve this by using the following code:
'/////////////////////////////////////////////////////////////////
Public Sub EndEditCurRow()
Dim intI As Integer
Dim drEditRow As DataRow()
Dim CurrentRow As DataRow
Dim dvNonVisibleMaxCount As Integer()
'CurrentRow is set to actual edited row
CurrentRow =
CType(grdAllColumnsCfg.BindingContext(grdAllColumnsCfg.DataSource,
grdAllColumnsCfg.DataMember).Current, DataRowView).Row
'Loop trough all columns and end edit mode on all columns
If grdAllColumnsCfg.TableStyles.Count > 0 Then
For intI = 0 To CurrentRow.Table.Columns.Count - 1
'grdAllColumnsCfg.TableStyles(0).GridColumnStyles.Count - 1
grdAllColumnsCfg.EndEdit(grdAllColumnsCfg.TableStyles(0).GridColumnStyles(in
tI), grdAllColumnsCfg.CurrentRowIndex, False)
Next
End If
'End Edit mode on actual row
CurrentRow.EndEdit()
End Sub
'/////////////////////////////////////////////////////////////////
This does not work when I want to ADD a row to the table. How can I make
this work?
I want to use myDataTable.GetChanges(DataRowState.Added) to detect if a row
has been added.
//Mats