I can't Bind Data on DataTemplate Controls

4 posts, 0 answers
  1. Mohamed
    Mohamed avatar
    4 posts
    Member since:
    Aug 2010

    Posted 16 Sep 2013 Link to this post

    Hi ,
     i have a sample app using Telerik WPF(trial Version) Grid View and i try to bind data on data Template control with no chance Please Help


    <telerik:RadGridView Name="DGV" ItemsSource="{Binding}" CanUserInsertRows="False" AutoGenerateColumns="False" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="300" Width="497"><br>            <telerik:RadGridView.Columns><br>                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name"><br>                    <telerik:GridViewDataColumn.CellTemplate><br>                        <DataTemplate><br>                            <Label Content="{Binding Name}"></Label><br>                        </DataTemplate><br>                    </telerik:GridViewDataColumn.CellTemplate><br>                </telerik:GridViewDataColumn><br>                <br>            </telerik:RadGridView.Columns><br>            <br>            <br>        </telerik:RadGridView><br><div></div>

    _________________________________________________________
    public MainWindow()<br>        {<br>            InitializeComponent();<br>            GetData();<br>        }<br><br>        public void GetData()<br>        {<br>            DataTable _dt = new DataTable();<br>            _dt.Columns.Add("ID");<br>            _dt.Columns.Add("Name");<br>            _dt.Columns.Add("Percentage");<br>            _dt.Rows.Add("1", "Ahmed", 25);<br>            _dt.Rows.Add("2", "Ali", 60);<br>            _dt.Rows.Add("3", "Mohamed", 80);<br>            _dt.Rows.Add("3", "Mohamed2", 50);<br><br>            DGV.DataContext = _dt;<br>        }
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Sep 2013 Link to this post

    Hello,

    Please set the ItemsSource for the RadGridView to be dt.DefaultView. Does this help?

    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Mohamed
    Mohamed avatar
    4 posts
    Member since:
    Aug 2010

    Posted 17 Sep 2013 Link to this post

    Great this fix my issue 
    But i don't know why ? can you explain that
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 18 Sep 2013 Link to this post

    Hello,

    DefaultView is the DataView for a DataTable. WPF internally transform this DefaultView to BindingListCollectionView. If you have set the ItemsSource to DataTable instead, then you will need to specify the property with [], i.e. [Name].

    Please note that the DataView is INotifyCollectionChanged and DataRowView is INotifyPropertyChanged and you will get changes automatically. 

     
    Regards,
    Didie
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
Back to Top