Multimobile Development: Building Applications for any Smartphone
sorting a dataset
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.


Scott Bansfield
GOOD ANSWER
I have a quick question about sorting a dataset. I have created a query:
Select top 10 * from authors I have put the results of this query into a
dataset and bound that to a datagrid. I have also enabled the AllowSorting
property on the datagrid. What I have done for sorting is appended "order
by table" with the corresponding table to my original query when the
sortcommand event is fired. However, this executes a brand new query and
returns a different set of data from the db. How can I sort the original
dataset based upon one of the columns being selected?

Thanks.

Reply to this message...
Vote that this is a GOOD answer... (28 votes from other users already)
 
 
    
Doug Rothaus \(MSFT\)
GOOD ANSWER
Instead of binding to the DataSet, create a DataViewManager for the DataSet
and bind to that. You can apply sort orders for each table in the DataSet
(via their corresponding DataView) using the DataViewSettings collection of
the DataViewManager. For example...

DataViewManager myDVM = new DataViewManager(myDS);

foreach (DataViewSetting myDVS in myDVM.DataViewSettings)
myDVS.Sort = "Name";

myGrid.SetDataBinding(myDVM, "RootTable");

Note, for single table binding, you can simply use a DataView instead of a
DataViewManager.

--
Doug Rothaus
Click here to reveal e-mail address

------------------------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.

"Scott Bansfield" <Click here to reveal e-mail address> wrote in message
news:uAG9aUBhBHA.1644@tkmsftngp05...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (26 votes from other users already)
 
 
    
Scott Bansfield
GOOD ANSWER
Thanks this works great. I knew there had to be a way that I could do this
and avoid doing it manually.

Scott

"Doug Rothaus (MSFT)" <Click here to reveal e-mail address> wrote in message
news:#f0kcnMhBHA.1596@tkmsftngp02...
> Instead of binding to the DataSet, create a DataViewManager for the
DataSet
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer... (28 votes from other users already)
 
 
 
System.Data.DataSet
System.Data.DataView
System.Data.DataViewManager
System.Data.DataViewSetting




Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734