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

GridViewDataColumn DataTemplate with DataType is not working

1 Answer 36 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Rene asked on 07 Mar 2014, 11:13 AM
Hey guys,
I've got a problem which is really frustrating. I am trying to display content based on its type in a RadGridView. Therefore I am using a DataTemplate referenced to a DataType. Sadly it seems like the DataType isnt beeing recognized at all. If I change the DataMemberBinding from "{Binding}" to a member of the object which is of type string - it is working but thats not what I need, i need it to be working with my own Data types(classes). 

<Window x:Class="RadControlsWpfApp1.MainWindow"
                Title="MainWindow" Height="350" Width="525">
        <telerik:RadGridView x:Name="Grid" Grid.Column="1" Margin="11,10,9,50" Grid.Row="1" ItemsSource="{Binding}" >
                <telerik:GridViewDataColumn IsReadOnly="True" Header="test" DataMemberBinding="{Binding}" >
                        <DataTemplate DataType="{x:Type local:Foo}">
                            <TextBlock Text="test" />

Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace RadControlsWpfApp1
    public class Foo
        public string Name { get; set; }
        public string Value { get; set; }
    public class Foo2
        public string Name { get; set; }
        public string Value { get; set; }
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
        public MainWindow()
            var list = new List<object> { new Foo2() { Name = "Brian2", Value = "val2" }, new Foo() { Name = "Brian", Value = "val1" } };
            Grid.DataContext = list;

1 Answer, 1 is accepted

Sort by
Telerik team
answered on 10 Mar 2014, 04:02 PM

Actually this is how the Binding works. As you set DataMemberBinding="{Binding}", 
the .ToString() method of the bound item (which is of type Foo2 or Foo) will be invoked and the result will be displayed in the cell.

If you would like to work with your full item, I can suggest you to use a Converter for the Binding and have the original item when the converter is evaluated. Another option would be to override the ToSting() methods of your classes and return the string you would like to have displayed.


DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

Asked by
Top achievements
Rank 1
Answers by
Telerik team
Share this question