PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Re: Bond DataGrid Row Deletion without delete key
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Re: Bond DataGrid Row Deletion without delete key
![]() |
Re: Bond DataGrid Row Deletion without delete key |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
There are two aspects to this (I am assuming that you are writing and
Windows Forms application and not an ASP.NET one, since you mentioned CurrentRowIndex in your original message). First, you don't need to delete anything from grid. All you need to do is delete it from the table and refresh the grid if necessary. Now the tricky bit is going to be determining which row in the grid matches which row in the table. Lets say you have a table of 10 rows, and you delete row 3. What was row 4 is now shown as row 3 in the datagrid, but since the table still holds the deleted row (flagged as deleted of course) indexing into the table won't work. Row 3 in the table will give you a deleted record. What you need is some more accurate method of identifying which row in the table you are pointing to on the grid. The solution is to use the CurrencyManager object. This can give you the precise row in the table, taking into account rows in the table that have been flagged as deleted, and enable you to delete it. For example CurrencyManager cm = (CurrencyManager) myDataGrid.BindingContext[myDataTable]; DataRowView row = (DataRowView) cm.Current; row.Delete(); This will delete the row currently selected in the grid from the table, by marking it as deleted, and remove the row from the grid as well. Hope that helps -- -------------------------------------------------------- Peter Wright (www.petewright.org) Author of ADO.NET Novice To Pro From Apress. www.apress.com "Arik Grinstein via .NET 247" <anonymous@dotnet247.com> wrote in message news:ubFhS1CQEHA.556@tk2msftngp13.phx.gbl... (Type your message here) -------------------------------- From: Arik Grinstein Hi. I have the following problem. I have a DataGrid bound to a DataTable. I am deleting elements from the DataGrid but not by pressing the delete key but by selecting a row and pressing a button outside the grid. The deletion from the grid is no problem but how do i delete from the Table since the CurrentRow is no longer a valid index that i can use to compare in the DataTable after the first delete. can someone give me an idea on how can I accomplish this? ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>st/sk6VjS06Z/8uHj5TWBA==</Id> |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

