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

I can't Bind Data on DataTemplate Controls

3 Answers 130 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mohamed
Top achievements
Rank 1
Mohamed asked on 16 Sep 2013, 09:29 AM
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>        }

3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 17 Sep 2013, 12:12 PM
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 >>
0
Mohamed
Top achievements
Rank 1
answered on 17 Sep 2013, 06:49 PM
Great this fix my issue 
But i don't know why ? can you explain that
0
Dimitrina
Telerik team
answered on 18 Sep 2013, 07:21 AM
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 >>
Tags
GridView
Asked by
Mohamed
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Mohamed
Top achievements
Rank 1
Share this question
or