Thanks
14 Answers, 1 is accepted
You should use the DataFormatString of the column like this:
<UserControl x:Class="TicketID_226294_RowDetailsCustom.MainPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" |
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"> |
<Grid> |
<telerik:RadGridView Name="clubsGrid" AutoGenerateColumns="False"> |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn |
Header="Price" |
DataMemberBinding="{Binding Price}" |
DataFormatString="{}{0:F}"> |
</telerik:GridViewDataColumn> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
</Grid> |
</UserControl> |
The F above is a fixed-point string format, but you can use any standard format as described here.
In C# you should omit the first pair '{}' since this is a special escape sequence for XAML only.
Also, you can check out our Data Formatting example.
I hope this helps.
Best wishes,
Ross
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.

Because our data are dynamically loaded from Database, we do not know column datatype until the DataGrid is loaded. Can we bind a converter to a column after the grid is already loaded. something like this
private serviceClient_GetDataCompletedHandler(DataTable dataTable)
{
_myGrid.ItemsSource = dataTable;
initColumnConverter():
}
private void initColumnConverter()
{
foreach(DataColumn col in _myGrid.Columns)
{
if(col.DataType.Equals(typeof(Double?)))
{
MyConverter converter= new MyConverter();
col.DataMemberBinding.Converter = converter;
col.DataMemberBinding.ConverterParameter = GetMyOwnFormatString():
}
}
}
I used lightweight DataTable that copies from a sample codes that showed somewhere in this forum.
I tried it without any error, but the convert function inside MyConverter is never executed, so the data display in double column is not formatted.
Any suggestions.
Thanks in advance.


rdgv1.ShowColumnFooters =
true;
rdgv1.Columns[
"Supplier_Name"].Footer = "Total Ref_Spend: ";
//rdgv1.Columns["Ref_Spend"].FormatString = "{0:#,###0.00;(#,###0.00);0}"; DataFormatString="{0:F}">
rdgv1.Columns[
"Ref_Spend"].DataFormatString = "{0:F}"; //does not work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
rdgv1.Columns["Ref_Spend"].Footer = txtblkDisplay1.Text;
but as you can see i am accessing the particular column i want by name through the Columns collection of my radgridview and want to set the its format but i cant, you can usually do something like this in aspnet
can you please put some code up...I mean in c# not in xaml it is quite easy to do in xaml but since i cant seem to access the DataformatString attrib/property in code without creating a new datacolumn, but i dont want to create a new datacolumn i want to access the existing one i have for each of my columns from my bound datasource, how do i do that????
thanks
Please try casting an existing column to GridViewDataColumn. This will give you access to the property.
Something like :
((GridViewDataColumn)this.RadGridView1.Columns[0]).DataFormatString = ... |
All the best,
Pavel Pavlov
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.

Posted 11 minutes ago (permalink)
gridMultiSelect.Columns.Add(CreateColumn("Phone", "Value")); |
GridViewDataColumn gridVDC = (GridViewDataColumn) gridMultiSelect.Columns[0]; |
gridVDC.DataFormatString = "{0:##-####-####}"; |
Can anyone tell me what I'm doing wrong? Thanks
-HEctor

void gridMultiSelect_DataLoaded(object sender, EventArgs e) |
{ |
foreach (GridViewColumn col in gridMultiSelect.Columns) |
{ |
if (col.Header.ToString().ToUpper() == "PHONE") |
{ |
for (int x = 0; x < gridMultiSelect.Items.Count; x++) |
{ |
ValidValue val = (ValidValue)gridMultiSelect.Items[x]; |
Int64 num = Convert.ToInt64(val.Value); |
val.Value = String.Format("{0:(###) ###-####}", num); |
} |
} |
} |
} |
Hi Hector,
I would highly recommend to store numeric values in numeric data types such as Int.
If for some reason that is not applicable to your project there is still a solution. Please use your custom IValueConverter for the Columns DataMemberBinding .
In the convert method of your custom value converter you may place the logic to translate the string to a formatted number.
In case you have troubles with this implementation just let me know, I will be glad to provide a sample.
Kind regards,
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.

void gridMultiSelect_DataLoaded(object sender, EventArgs e) |
{ |
for (int x = 0; x < gridMultiSelect.Columns.Count; x++) |
{ |
if (gridMultiSelect.Columns[x].Header.ToString().ToUpper() == "PHONE") |
{ |
GridViewDataColumn gridVDC = (GridViewDataColumn)gridMultiSelect.Columns[x]; |
gridVDC.DataMemberBinding.Converter = new PhoneDataConverter(); |
gridVDC.Width = new GridLength(100); |
} |
} |
} |
The converter:
public class PhoneDataConverter : IValueConverter |
{ |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
{ |
Int64 num; |
if( Int64.TryParse(value.ToString(), out num)) |
return String.Format("{0:(###) ###-####}", num); |
else |
return value.ToString(); |
} |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
{ |
throw new NotImplementedException(); |
} |
} |

Imports System
Imports System.Text.RegularExpressions
Public Class PhoneDataConverter
Implements Data.IValueConverter
Public Function Convert(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.Convert
Dim num As Int64
If Int64.TryParse(value.ToString(), num) Then
Return [String].Format("{0:(###) ###-####}", num)
Else
Return value.ToString()
End If
End Function
Public Function ConvertBack(ByVal value As Object, ByVal targetType As System.Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements System.Windows.Data.IValueConverter.ConvertBack
Dim newvalue = Regex.Replace(value, "[- )(]", String.Empty)
Return newvalue
End Function
End Class

Telerik silverlight datagrid remove leading zero during export like "0001" exported as "1"
Is there any solution for this?

Did the IValueConverter not work for you? Use the example shown, but instead of returning a string format, return an int. This has been over six years, so I can't remember the exact solution, but I did use the IValueCovnerter.

As suggested in a previous reply by my colleague, the built-in mechanism for formatting a column through XAML is by using the DataFormatString property. Can you please share your obstacles to using it, or I am missing something?
Regards,
Stefan X1
Telerik