Home Forums WinForms controls Xceed Grid for WinForms Cell numerical formatting

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #14707 |

    We are currently evaluating the Xceed Grid and it seems to the component satisfies our needs. We are currently working on an application which displays results of a query in a Grid. Also there are several property grids (based on Xceed Grid), which make enable to set the Result Grid’s properties, for example colors, formatting, grouping, and so on…

    The question is that if a cell contains numerical value how to format it?

    For example the following data is coming from the DB:

    3.18
    3.1415
    3.00

    I want to round every cell value, somehow like this: #,##0.0 – where the result would be:

    3.2
    3.1
    3.0

    Where #,##0.0 is the format string which contains information about the number of decimal places, the thousand separator, and so on. If I set the format string based on the manual, the values are never rounded, so for example 3.1415 never will be 3.1 (in the case of 1 decimal place), the values are not rounded.

    I browsed the Help, but unfortunately I couldn’t figured out how to round the values. Alternatively I could create a new CellViewerManager to display the rounded values correctly, but I don’t want to go this way, if there is another easier way to achieve this.

    Is there any way to do this ?

    Imported from legacy forums. Posted by Szabolcs (had 3581 views)

    User (Old forums)
    Member
    Post count: 23064

    I tried to use the WinNumericTextBox control, but still no success to format:

    WinNumericTextBox w = new WinNumericTextBox(false);
    w.BorderStyle = EnhancedBorderStyle.None;
    w.DataType = typeof(System.Decimal);
    w.Decimals = 1;

    c.CellViewerManager = new Xceed.Grid.Viewers.NumericViewer(w);

    For example: 1092.75 will be after that I changed the CellViewerManager 1092.75.

    If I change the datatype to Int32, then the decimal would disappear – this is correct.
    If I change the datatype to Double, then nothing changed.

    If I could make the w.Decimals to work, then the problem could be solved!

    Imported from legacy forums. Posted by Szabolcs (had 487 views)

    User (Old forums)
    Member
    Post count: 23064

    I’m not totally sure I understand if you want rounding or not, but if you do not want to use the CellEditor/ViewerManager, you can use the FormatSpecifier property on the cell to set it :

    <i>
    dataRowTemplate1.Cells[ index ].FormatSpecifier = “#,##0.0 “;
    </i>

    Imported from legacy forums. Posted by André (had 334 views)

    User (Old forums)
    Member
    Post count: 23064

    Thank you, Andre!

    This is exactly, what I want! Also it works for columns, so I can set the whole column’s format easily in one step!

    Excellent!

    Imported from legacy forums. Posted by Szabolcs (had 4118 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.