Add row to datatable from datagrid without leaving current row with cursor 
Author Message
 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



Mon, 10 Oct 2005 17:59:16 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. adding a table row, without setting same defaults as previous row

2. Know datatable row number of a datagrid line ?

3. Trouble adding rows to DataTable : Error = System.IndexOutOfRangeException: Cannot find column 2

4. problems adding datatable row in code - overrideable error

5. Event called on adding row in dataTable

6. AutoIncrement and method DataTable.Rows.Add(Object())

7. Help! Cursor jumps left when moving between rows

8. Help: DBGrid - how to make DBGrid.row = current row when I click the a cell

9. Help: DBGrid - how to make DBGrid.row = current row when I click the a cell

10. How to commit datagrid's current row?

11. datagrid: current row is not available

12. DataGrid current row

 

 
Powered by phpBB® Forum Software