Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do strings sort in a DataView?

Status
Not open for further replies.

CrashDome

Technical User
Jan 7, 2002
86
US
I'm trying to sort a datatable in a datagrid by a column with a string value. There are certain items I would like towards the bottom of the list that would normally have a {null} value in the string column. A quick fix was to populate them with a character value higher than any alphabetic character. That way they would always be sorted last. However, I ran into what I consider very odd behavior. The character (a "~") sorted first?!?!?

Could someone elaborate as to how a dataview performs a sort on a string?

To see the odd behavior I describe create a form and drop ina datagrid (called "dataGrid1"). Drop this into the form's load event:


DataTable dt = new DataTable("test");
dt.Columns.Add("char",Type.GetType("System.String"));

dt.Rows.Add(new object[] {"Z"});
dt.Rows.Add(new object[] {"V"});
dt.Rows.Add(new object[] {"\u007B"});
dt.Rows.Add(new object[] {"A"});
dt.Rows.Add(new object[] {"\u007C"});
dt.Rows.Add(new object[] {"\u007D"});
dt.Rows.Add(new object[] {"\u007E"});
dt.Rows.Add(new object[] {"\u005A"});
dt.Rows.Add(new object[] {"\u0041"});

DataView dv = new DataView(dt,"","char ASC",DataViewRowState.CurrentRows);
dataGrid1.DataSource = dv;


What is going on here? I thought the sort was done on Unicode values?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top