Sort a price column in a dataview

  • Thread starter Thread starter Mark Gilbert
  • Start date Start date
M

Mark Gilbert

The only way i could see to insert prices into a datagrid was to use
strings.
Heres a fragment...

oTable.Columns.Add(New DataColumn("Price", GetType(String)))
..
..
..
oRow("Price") = nPrice.ToString("C")
..
..
..
oSpecs = New DataView(oTable)
oSpecs.Sort = "Price"

Now the problem is, the column is obviously being sorted as regards to
a string rather than a currency. For instance i end up with it
ordered like this...

£1,100.50
£400.00
£700.50
£800.70

Is there any way to make the datagrid aware that a column contains
currency values? I couldn't find an appropriate datatype.
 
Hi Mark,

Why don't you set currency symbol in column header and leave decimal (or
other numeric) type?
 
I'm not altogether sure what you mean. Do you mean just have something
like "Price (£)" as the column title? I'd much rather display a pound
sign prefixed to each number. Also, is it possible to set a
double/float to 2 decimal places without unfortunate things happening
such as it ending up being rounded up?

Miha Markic said:
Hi Mark,

Why don't you set currency symbol in column header and leave decimal (or
other numeric) type?

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
SLODUG - Slovene Developer Users Group
www.rthand.com

Mark Gilbert said:
The only way i could see to insert prices into a datagrid was to use
strings.
Heres a fragment...

oTable.Columns.Add(New DataColumn("Price", GetType(String)))
.
.
.
oRow("Price") = nPrice.ToString("C")
.
.
.
oSpecs = New DataView(oTable)
oSpecs.Sort = "Price"

Now the problem is, the column is obviously being sorted as regards to
a string rather than a currency. For instance i end up with it
ordered like this...

£1,100.50
£400.00
£700.50
£800.70

Is there any way to make the datagrid aware that a column contains
currency values? I couldn't find an appropriate datatype.
 
Back
Top