The users need to be able to sort on any datagridview column.
This is the code that I am using.
The fetch win button has this code
sodCustomers = SODCustomers.GetSODCustomers(criteria);
.SortedBindingList<SODCustomer> sortedList =
new SortedBindingList<SODCustomer>( sodCustomers );
sortedList.ApplySort( "Moniker", ListSortDirection.Ascending );
this.sodCustomersBindingSource.DataSource = sortedList;
In the Save button have this to save the current selected row
SODCustomer currentCustomer = (SODCustomer) sodCustomersBindingSource.Current;
sodCustomers.SaveItem( currentCustomer );
Anybody sees anything wrong with the above?
Thanks
I'm not sure you have to manually save the current item. When the user leaves that row, data binding will call ApplyEdit() for you, which will trigger the item to save itself.
Your binding code looks right though. Remember that the grid control will automatically allow the user to sort by any column when bound to a SortedBindingList, so while you start sorting by Moniker, the user can change the sort dynamically.
Each row is indepentent from the rest of the rows. It is usual for a user to save something without leaving the row and then exit. It does save automatically when moving. Thanks for verifing the code.
OK, got it. In that case though, you need to manually call
EndEdit() on the bindingsource before trying to save your object. I think
(haven’t tested) that calling EndEdit() on the bindingsource will trigger
the save operation on the current row all by itself.
In any case, you need the EndEdit() to get the edit level back
to zero.
Rocky
From: GeorgeG
[mailto:cslanet@lhotka.net]
Sent: Tuesday, February 06, 2007 4:30 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Is this the right way to allow sorting on any
datagridview column and save the bus root object
Each row is indepentent from the rest of the rows. It is usual for a
user to save something without leaving the row and then exit. It
does save automatically when moving. Thanks for verifing the code.
Copyright (c) Marimer LLC