Hi Telerik team,
I have a project with a requirement to display numeric value depending on dynamic unit format in radgridview or radtreelistview.
I bind my radtreelistview to list of object from class below =>
for example : ObservableCollection<MyVariable> obj = new ObservableCollection<MyVariable>();
radTreeListView1.ItemsSource = obj;
below is my xaml code for the grid.
I also have a converter class to handle the DataFormatString
When I run these codes. it never run through the code in numberConverter class. but if i change DataFormatString code in xaml code to
It run through the numberConverter codes. if i put a break point in this line of code
when i checked the type of "value" from above code. instead of "CellValue" it showed "[ProjectNamespace].MainWindow" as type of value.
I followed the code from this thread
http://www.telerik.com/community/forums/wpf/gridview/dataformatstring.aspx
but it will bind the value as string and not double which causing the cell to be able to accept non numeric value.
Please suggest how to achieve this dynamic DataFormatString binding.
Thanks.
Andy
I have a project with a requirement to display numeric value depending on dynamic unit format in radgridview or radtreelistview.
I bind my radtreelistview to list of object from class below =>
for example : ObservableCollection<MyVariable> obj = new ObservableCollection<MyVariable>();
radTreeListView1.ItemsSource = obj;
public class MyVariable : ViewModelBase, INotifyPropertyChanged{ public string Name { get; set; } public CellValue First { get; set; } public CellValue Second { get; set; } public CellValue Third { get; set; } public string Remarks { get; set; } public ObservableCollection<MyVariable> ChildCollection { get; set; } } public class CellValue : INotifyPropertyChanged { public string Key { get; set; } public double? Value { get; set; } public string Unit { get; set; } public string Location { get; set; } public bool IsEditable { get; set; } }below is my xaml code for the grid.
<telerik:RadTreeListView x:Name="radTreeListView1" AutoGenerateColumns="False" RowIndicatorVisibility="Collapsed" RowLoaded="radTreeListView1_RowLoaded" RowIsExpandedChanging="radTreeListView1_RowIsExpandedChanging"> <telerik:RadTreeListView.ChildTableDefinitions> <telerik:TreeListViewTableDefinition ItemsSource="{Binding ChildCollection}" /> </telerik:RadTreeListView.ChildTableDefinitions> <telerik:RadTreeListView.Columns> <telerik:GridViewDataColumn Header="Parameters" DataMemberBinding="{Binding Name}" IsReadOnly="True" Width="auto" /> <telerik:GridViewDataColumn Header="First Value" DataMemberBinding="{Binding First.Value, Mode=TwoWay}" DataFormatString="{Binding First.Unit, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding First.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" /> <telerik:GridViewDataColumn Header="Second Value" DataMemberBinding="{Binding Second.Value, Mode=TwoWay}" DataFormatString="{Binding Second.Unit, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding Second.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" /> <telerik:GridViewDataColumn Header="Third Value" DataMemberBinding="{Binding Third.Value, Mode=TwoWay}" DataFormatString="{Binding Third.Unit, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding Third.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" /> <telerik:GridViewDataColumn Header="Remarks" DataMemberBinding="{Binding Remarks}" IsReadOnly="True" Width="*" /> </telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>I also have a converter class to handle the DataFormatString
public class NumberConverter : IValueConverter{ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { CellValue cellValue = value as CellValue; if (cellValue != null && cellValue.Unit == "%") { return "{0:p2}"; } else return "{0:n2}"; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return value; }}When I run these codes. it never run through the code in numberConverter class. but if i change DataFormatString code in xaml code to
<telerik:GridViewDataColumn Header="First Value" DataMemberBinding="{Binding First.Value, Mode=TwoWay}" DataFormatString="{Binding First, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding First.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" />
<telerik:GridViewDataColumn Header="Second Value" DataMemberBinding="{Binding Second.Value, Mode=TwoWay}" DataFormatString="{Binding Second, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding Second.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" />
<telerik:GridViewDataColumn Header="Third Value" DataMemberBinding="{Binding Third.Value, Mode=TwoWay}" DataFormatString="{Binding Third, Converter={StaticResource numberConverter}}" IsReadOnlyBinding="{Binding Third.IsEditable}" CellStyleSelector="{StaticResource cellStyle}" Width="auto" />It run through the numberConverter codes. if i put a break point in this line of code
CellValue cellValue = value as CellValue; when i checked the type of "value" from above code. instead of "CellValue" it showed "[ProjectNamespace].MainWindow" as type of value.
I followed the code from this thread
http://www.telerik.com/community/forums/wpf/gridview/dataformatstring.aspx
but it will bind the value as string and not double which causing the cell to be able to accept non numeric value.
Please suggest how to achieve this dynamic DataFormatString binding.
Thanks.
Andy
