Topaz Filer: if you use e-mail for business, we can save you money and decrease your risk.
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... (1 vote from another user already)
 
 
    
Doug Rothaus \(MSFT\)
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...
 
Auto-following on Twitter
Ubuntu and XP on one “desktop”
 
    
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... (1 vote from another user already)
 
 
 
System.Data.DataSet
System.Data.DataView
System.Data.DataViewManager
System.Data.DataViewSetting




Ad
BootFX
Reliable and powerful .NET application framework.
Recession Busting Bespoke Software
Get through the recession by investing in bespoke software to decrease costs and create commercial opportunities.
Other DN247 Network Sites
.NET 247
SQL Server Wins
Old Skool Developer
 
Copyright © AMX Software Ltd 2008-2009. Portions copyright © Matthew Baxter-Reynolds 2001-2009. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - .NET 247 is a member of the DN247 Network - 4.0.30129.1734