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
columnsstart column editor - pick column
- click
defaultcellstyleproperty - for
format, click...button select list.numeric,2 decimalsresults inn2
if store numeric values in column, 2 decimal places display, actual/original value still available , sorting using numeric value rather text sort.
Comments
Post a Comment