PC Review


Reply
Thread Tools Rate Thread

Datagrid number sorting

 
 
Mike
Guest
Posts: n/a
 
      20th Nov 2006
I'm passing a number to a datagrid but when I sort on that column its
sorting it as a string, not a number. eg 100 comes before 2.

eg
//Get Key from an array of objects
.....
dr["Instrument Key"] = System.Convert.ToDecimal(RatesArray[i,4]);
.....

DataGridTextBoxColumn instrumentKeyColumn = new
DataGridTextBoxColumn();
instrumentKeyColumn.MappingName="Instrument Key";
instrumentKeyColumn.HeaderText = "Instrument Key";
instrumentKeyColumn.Width = 80;
instrumentKeyColumn.Alignment = HorizontalAlignment.Right;
//instrumentKeyColumn.Format="n0";
dgts.GridColumnStyles.Add(instrumentKeyColumn);
.....

Any idea what I'm doing wrong?

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2lhcmFuIE8nJ0Rvbm5lbGw=?=
Guest
Posts: n/a
 
      20th Nov 2006
You need to ensure the datagrid knows its a number. The best way I think to
do things like this is to make a datatable with the column of the right type.
Then you can bind the grid to the datatable and do sorting and filtering on
the table.

Ciaran O'Donnell

"Mike" wrote:

> I'm passing a number to a datagrid but when I sort on that column its
> sorting it as a string, not a number. eg 100 comes before 2.
>
> eg
> //Get Key from an array of objects
> .....
> dr["Instrument Key"] = System.Convert.ToDecimal(RatesArray[i,4]);
> .....
>
> DataGridTextBoxColumn instrumentKeyColumn = new
> DataGridTextBoxColumn();
> instrumentKeyColumn.MappingName="Instrument Key";
> instrumentKeyColumn.HeaderText = "Instrument Key";
> instrumentKeyColumn.Width = 80;
> instrumentKeyColumn.Alignment = HorizontalAlignment.Right;
> //instrumentKeyColumn.Format="n0";
> dgts.GridColumnStyles.Add(instrumentKeyColumn);
> .....
>
> Any idea what I'm doing wrong?
>
>

 
Reply With Quote
 
MAH
Guest
Posts: n/a
 
      20th Nov 2006
Thanks for the idea but I'm not going to create another in memory copy
of my data just to do that, the data set in the array is already big
enough.

I guess the users will just have to live with an invalid sort or pay
for a better data grid control if the standard one is not smart enough
to know its being passed a number instead of a string.

Mike


Ciaran O''Donnell wrote:
> You need to ensure the datagrid knows its a number. The best way I think to
> do things like this is to make a datatable with the column of the right type.
> Then you can bind the grid to the datatable and do sorting and filtering on
> the table.
>
> Ciaran O'Donnell
>
> "Mike" wrote:
>
> > I'm passing a number to a datagrid but when I sort on that column its
> > sorting it as a string, not a number. eg 100 comes before 2.
> >
> > eg
> > //Get Key from an array of objects
> > .....
> > dr["Instrument Key"] = System.Convert.ToDecimal(RatesArray[i,4]);
> > .....
> >
> > DataGridTextBoxColumn instrumentKeyColumn = new
> > DataGridTextBoxColumn();
> > instrumentKeyColumn.MappingName="Instrument Key";
> > instrumentKeyColumn.HeaderText = "Instrument Key";
> > instrumentKeyColumn.Width = 80;
> > instrumentKeyColumn.Alignment = HorizontalAlignment.Right;
> > //instrumentKeyColumn.Format="n0";
> > dgts.GridColumnStyles.Add(instrumentKeyColumn);
> > .....
> >
> > Any idea what I'm doing wrong?
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you map DataGrid rows to it's DataSource when sorting a DataGrid? aualias Microsoft Dot NET Framework Forms 2 13th Sep 2005 06:09 PM
Sorting on multiple number & letter/number combinations =?Utf-8?B?SmltIEou?= Microsoft Access Reports 4 13th Sep 2005 05:45 PM
Sorting in Datagrid =?Utf-8?B?YWxhbg==?= Microsoft ASP .NET 0 21st Apr 2005 06:16 PM
No sorting event available when sorting DataGrid columns!!! =?Utf-8?B?TmFk?= Microsoft Dot NET Framework Forms 2 21st Apr 2005 02:47 PM
Sorting on a datagrid? Tavish Muldoon Microsoft Dot NET 1 3rd Jul 2003 09:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:04 AM.