Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2005

Tip: Looking for answers? Try searching our database.

How do you map DataGrid rows to it's DataSource when sorting a DataGrid?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aualias - 08 Sep 2005 21:27 GMT
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
Bart Mermuys - 09 Sep 2005 13:45 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.