473,407 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Sorting DataViews

DataView d = new DataView(state.getPlayers());

d.Sort = "Name ASC";
foreach(DataRow dr in d.Table.Rows)

{

dataMenu.Items.Add(new
DataItem(dr["Name"].ToString(),dr["File"].ToString()));

}

Please could someone tell me why this isn't sorting the names in
alphabetical order?

Many thanks
Nov 17 '05 #1
1 1134
> foreach(DataRow dr in d.Table.Rows)

This line is the problem. You are using a DataView to sort, yet you are accessing the underlying table directly.
In order to use the sorted data, you must query the table *through* the DataView you created:

DataView view = new DataView(state.getPlayers());
view.Sort = "Name";

foreach (DataRowView row in view)
// Notice how the view is enumerates "DataRowView" objects
{
dataMenu.Items.Add(new DataItem(row["Name"].ToString(), row["File"].ToString()));
}

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"Terry McNamee" <n/a> wrote in message news:uX**************@tk2msftngp13.phx.gbl...
DataView d = new DataView(state.getPlayers());

d.Sort = "Name ASC";
foreach(DataRow dr in d.Table.Rows)

{

dataMenu.Items.Add(new DataItem(dr["Name"].ToString(),dr["File"].ToString()));

}

Please could someone tell me why this isn't sorting the names in alphabetical order?

Many thanks

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Darryn Ross | last post by:
Hi, I am trying to disable the datagrids ability to sort by it's column headings??? how do i do this? i have set dg.AllowSorting = false but this doesn't make any difference. Thankz Darryn
2
by: Sriram | last post by:
hi, i have loaded the listbox with the data from a database using dataset. i am finding difficulty in sorting the data. i am not able to find a method to sort data. any help in this regard...
4
by: Mark Travis | last post by:
Hi all, I have written a simple Web Application that displays a query result onto a page using the ASP DataGrid. To Digress ======= Development information about the page is as follows 1....
7
by: Jason | last post by:
Is it possible to somehow sort a dataview, all on one column, but on different variables? That is, I have a 'Title' column in my dataview and I'd like to display first all "Directors" (sorted),...
0
by: Daniel Bass | last post by:
I've already posted this in the asp forum, and other asp.net forums on the net with no luck... I've got a data grid, with paging, and sorting allowed. I can find loads of examples, and have...
3
by: Jerry | last post by:
Hi, I have a couple of datagrids that are based on dataviews. If I filter dataview1 I would like to automatically filter dataview2. I posted something about this before but I think I didn't...
5
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
4
by: Bernie Hunt | last post by:
I currently have a datagrid that I'm feeding with a DataSet, which contains three tables. I would like to use a DataView to format the DataTables but I'm not sure how to go about this. Currently...
0
by: anujsharma181 | last post by:
Hi I am trying to sort the child table. Here's the complete scenario. I have used web services to get values in the data set. There are 2 tables T1 and T2 for data sets and they have a parent child...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.