This is a migrated thread and some comments may be shown as answers.

Set the format string through the designer

1 Answer 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 29 Sep 2016, 05:25 PM

I need to format this "123456789" to this "12-3456789" in a column.
I know I can do this in the code, but is there a way to do this through the designer?
I tried setting the FormatString of the GridViewTextBoxColumn to {0:##-#######} but that doesn't seem to do anything.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 30 Sep 2016, 10:16 AM
Hello P G,

Please note that columns that contain text cannot be automatically formatted. To achieve this you need to manually format the value (parse it to numeric or another format) which can be done in the CellFormating event:
private void RadGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
{
    if (e.Column.Name == "column1" && e.CellElement.Value != null)
    {
 
        int value = int.Parse(e.CellElement.Value.ToString());
        e.CellElement.Text = string.Format("{0:##-#######}", value);
    }
}

Do not hesitate to contact us if you have other questions.
 
Regards,
Dimitar
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GridView
Asked by
Pavel
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or