vb.net - Populate DataGridView Column With a Double forcing to 2 Decimal Places, with Sort -


sorry weird title didn't know how phrase better.

i'm trying populate column on datagridview number has 2 decimal places.

to i'm using

dim _size double = 1.2345 datagridview1.item(0, 0).value = format(_size, "0.00") 

this populates data correctly, when sorting column, treats item string.

i found on net, if convert data being entered number type (double, integer etc..), sort number instead of string. works brilliantly, values integers 2 decimal places (i.e. 1.00) changed 0 decimal places.

so, if had following values

1.2345 2.2345 3.2345 4.2345 5.0011 

and formatted 2 decimal places become

1.23 2.23 3.23 4.23 5.00 

if converted them doubles become

1.23 2.23 3.23 4.23 5 

is there way of populating datagridview these values formatted 2 decimal places keeping double type column sorts correctly?

i hope i've explained clearly.

any appreciated

you converting values string using legacy vb format function:

function format(expression object, optional style string = "") string 

when converted, other decimals lost. use format property of defaultcellstyle column specify number of decimal places want (n2 2 decimals). unlike vb's format, acts "displayas" without altering value or changing type.

  • in properties pane, select columns start column editor
  • pick column
  • click defaultcellstyle property
  • for format, click ... button select list. numeric , 2 decimals results in n2

if store numeric values in column, 2 decimal places display, actual/original value still available , sorting using numeric value rather text sort.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -