Formatting GridViewDecimalColumn

4 posts, 1 answers
  1. Curtis
    Curtis avatar
    16 posts
    Member since:
    Nov 2010

    Posted 19 Oct 2011 Link to this post

    Hey there,

    I was wondering how to go about formatting a value within a DecimalColumn. When creating the column, I set decimal places to 5:

    decimalBoxColumn = New GridViewDecimalColumn
    decimalBoxColumn.DataType = GetType(Decimal)
    decimalBoxColumn.Name = "Quantity"
    decimalBoxColumn.FieldName = "Quantity"
    decimalBoxColumn.AllowSort = False
    decimalBoxColumn.TextAlignment = ContentAlignment.MiddleRight
    decimalBoxColumn.DecimalPlaces = 5
    decimalBoxColumn.HeaderText = "Quantity"
    decimalBoxColumn.HeaderTextAlignment = ContentAlignment.MiddleRight
    decimalBoxColumn.MaxWidth = 100
    BomRadGridView.MasterTemplate.Columns.Add(decimalBoxColumn)

    When using the spin edit controls to modify the value, everything stays formatted correctly (the displayed value contains five decimal places). However, if the user types a value into the spin edit (rather than using the up and down arrows), the value will stay exactly as they input - it will not format it to the five decimal display. So if a user types 2.5, that value sticks in there. Is there a way so that if the user enters 2.5, when they leave the cell it will be formatted to 2.50000?

    Thanks in advance.
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 20 Oct 2011 Link to this post

    Hello Thabani,

    Thank you for your question. 

    You can achieve the desired behavior by setting the FormatString property of the column. Here is how to achieve it:
    decimalBoxColumn.FormatString = "{0:F5}";

    I hope that you find this information helpful. Should you have any other questions, do not hesitate to contact us.
     
    Best wishes,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

  3. Curtis
    Curtis avatar
    16 posts
    Member since:
    Nov 2010

    Posted 20 Oct 2011 Link to this post

    Works beautifully. I explored the FormatString property, however I wasn't utilizing it correctly. Thanks a million!
  4. Stefan
    Admin
    Stefan avatar
    2908 posts

    Posted 21 Oct 2011 Link to this post

    Hello Thabani,

    I am glad that I could help. Should you have any other questions, do not hesitate to contact us.
     
    Regards,
    Stefan
    the Telerik team

    Q2’11 SP1 of RadControls for WinForms is available for download (see what's new); also available is the Q3'11 Roadmap for Telerik Windows Forms controls.

Back to Top