updating datagrid

  • Thread starter Thread starter Nanda
  • Start date Start date
N

Nanda

hi,
i have an editable datagrid. how can i update the
database, When the user completes entering data for a row.
i.e., data should be updated whenever user completes
entering a row.

Thanks in advance.
 
Nanda,

In this case, you will have to hook into the grid and catch when the row
changes. When this happens, you will have to access the data adapter that
created the data set that the grid bound to, and pass the data set to the
adapter through the Update method.

Hope this helps.
 
To add some details:

OnCurrentCellChanged should be overridden to determine when the user is
moved to the next row.

Then the row state should be analyzed, and if the underlying data row has
been changed, changes should be propagated to the database.

Current underlying data row can be obtained like this:

CurrencyManager cm = (CurrencyManager)grid.BindingContext[grid.DataSource,
grid.DataMember];

DataView view = (DataView)cm.List;

DataRow currentRow = view[grid.CurrentCell.RowNumber].Row;

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Unit Testing and Integration Environment
http://x-unity.miik.com.ua
Deliver reliable .NET software

Nicholas Paldino said:
Nanda,

In this case, you will have to hook into the grid and catch when the row
changes. When this happens, you will have to access the data adapter that
created the data set that the grid bound to, and pass the data set to the
adapter through the Update method.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Nanda said:
hi,
i have an editable datagrid. how can i update the
database, When the user completes entering data for a row.
i.e., data should be updated whenever user completes
entering a row.

Thanks in advance.
 
Back
Top