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

Format Grid Columns make string!

1 Answer 40 Views
This is a migrated thread and some comments may be shown as answers.
noman nadeem
Top achievements
Rank 1
noman nadeem asked on 27 Aug 2009, 06:10 PM
i want to format telerik grid column , i have text in the grid but its shows like that 00000000AB in this format i want to show only AB
which format should i used please reply me how to handle it.

i used code like that :
<telerik:GridViewDataColumn HeaderText="Sub Heading" DataMemberBinding="{Binding subheadingname3}" DataFormatString="{}{0:G}" TextAlignment="Left" />


1 Answer, 1 is accepted

Sort by
Telerik team
answered on 28 Aug 2009, 05:52 AM
Hi noman nadeem,

Well, the easiest way to do that is to introduce a new property for your data objects called ShortHeading and bind to that property instead. I far as I know it is not possible to return a substring using format strings.

Another approach is to create a simple CellTemplate for that column and use a converter to trim the original value. Here is a sample:

public class SubstringConverter : IValueConverter  
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)  
        string stringValue = System.Convert.ToString(value);  
        int lenght = System.Convert.ToInt32(parameter);  
        if(lenght >= 0)  
            return stringValue.Substring(0, Math.Abs(lenght));  
            return ReverseString(ReverseString(stringValue).Substring(0, Math.Abs(lenght)));  
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)  
        throw new NotImplementedException();  
    public static string ReverseString(string strinToReverse)  
        char[] stringArray = strinToReverse.ToCharArray();  
        return new string(stringArray);  

    <local:SubstringConverter x:Key="StringConverter"/>  
<Grid x:Name="LayoutRoot" Background="White">  
    <telerikGrid:RadGridView Name="RadGridView1" AutoGenerateColumns="False">  
            <telerikGrid:GridViewDataColumn HeaderText="Sub Heading"   
                                        DataMemberBinding="{Binding subheadingname3}" 
                        <TextBlock Text="{  
                            Binding Path=subheadingname3,   
                            Converter={StaticResource StringConverter},   

The ConverterParameter controls which part of a string is returned. When you specify a value of -2 the last two characters will be returned.

Hope this helps.

the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
noman nadeem
Top achievements
Rank 1
Answers by
Telerik team
Share this question