I have a DataGrid and I want the user to be able to delete rows. When the
grid is not sorted the index of the DataGrid corresponds to the row in the
DataTable that is the datasource.
However, if I sort, the DataGrid seems to be keeping track of the order.
The CurrencyManager acts as if the DataGrid is not sorted and the wrong row
gets deleted.
How can I keep track of the sorting so that I can delete the correct row?
Thanks.
David
Hi,
>I have a DataGrid and I want the user to be able to delete rows. When the
>grid is not sorted the index of the DataGrid corresponds to the row in the
[quoted text clipped - 3 lines]
> The CurrencyManager acts as if the DataGrid is not sorted and the wrong
> row gets deleted.
That's because it's actually (internally) bound to a DataView and not a
DataTable.
> How can I keep track of the sorting so that I can delete the correct row?
- The CurrencyManager has a property called Current, which returns the
current DataRowView.
CurrencyManager cm =
(CurrencyManager)BindingContext[dataGrid1.DataSource,dataGrid1.DataMember];
DataRowView currentDRV = (DataRowView)cm.Current;
- DataRowView has a Delete method, but if you want you can get the DataRow
from it:
DataRow currentRow = currentDRV.Row;
HTH,
Greetings
> Thanks.
>
> David
aualias - 13 Sep 2005 18:09 GMT
Bart,
Thanks. That makes sense. I shall give it a try.
David
> Hi,
>
[quoted text clipped - 29 lines]
>>
>> David