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

Update continuously datagrid with data from a list

7 Answers 1501 Views
DataGrid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Densi
Top achievements
Rank 1
Densi asked on 05 Apr 2016, 04:32 PM

Hello,

i'm programming an UWP app, i need to bind a list to the RadDataGrid, this datagrid must be updated each time when data changes in the list.
For now i can populate my datagrid with the data, but it doesn't update when the data changes in the list (name of list: Inputs)

This is my xaml code: 

1.<Grid:RadDataGrid x:Name="DataGridTel" HorizontalAlignment="Left" Height="269" Margin="233,10,0,0" Grid.Row="1" VerticalAlignment="Top" Width="388" ItemsSource="{Binding Inputs}">
2.   <Grid:RadDataGrid.Columns>
3.      <Grid:DataGridTextColumn CanUserEdit="True" Header="Code" PropertyName="Code"/>
4.      <Grid:DataGridTextColumn Header="Value" PropertyName="Value"/>
5.   </Grid:RadDataGrid.Columns>
6.</Grid:RadDataGrid>
And this is c# code: 
1.DataGridTel.DataContext = Hardware.BoardDC;

BoardDC is my class where i have the list -> "Inputs" that i'm binding to ItemsSource property of telerik datagrid.

Inputs list is a list of analog input channels and has a lot of parameters, but i want to show in the datagrid only name and value parameters (it works) .

I tried differents ways to do that but nothing works, i shown this way because using a telerik chart it's working, i can see data changes on my chart if i edit the list that i bind to the chart, but i can't do the same with data grid.

Anyone can help me? 

Thanks!

7 Answers, 1 is accepted

Sort by
0
Densi
Top achievements
Rank 1
answered on 07 Apr 2016, 06:51 AM
Someone can help me?
0
Densi
Top achievements
Rank 1
answered on 07 Apr 2016, 12:19 PM

I solved in part the problem, instead of List<T> i used ObservableCollection<T> and now the datagrid source is updated when data changes in my list but graphycally didn't change anything on the datagrid, i need to scroll up and down the data grid to see data changes... it looks like the datagrid needs a refresh, exist something like to datagridname.Refresh();  
In the web i found this: radGridViewName.MasterTemplate.Refresh(null);  but MasterTemplate doesn't exist, maybe because this is not for telerik UWP

Someone know a method for refresh the datagrid? 

Thanks

0
Densi
Top achievements
Rank 1
answered on 07 Apr 2016, 12:24 PM
I also tried dataGridName.UpdateLayout(); but nothing changes.... 
0
Accepted
Ivaylo Gergov
Telerik team
answered on 11 Apr 2016, 09:38 AM
Hello Denis,

Sorry for the late response.

Generally, indeed you should use a collection which implements the INotifyCollectionChagned interface for example ObservableCollection and also your business item should implement the INotifyPropertyChanged interface.

Could you please verify that these two requirements are met? If not, could you please send us a sample project which reproduces the issue?

I am looking forward to your reply.

Regards,
Ivaylo Gergov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Densi
Top achievements
Rank 1
answered on 12 Apr 2016, 09:55 AM

Hello Ivaylo,
thank you for your reply, before your reply, i've tried to implement INotifyPropertyChanged interface but it wasn't working, then i solved my problem through another my class, in this class i simply checked when a value of an item of my collection was changed, then if a value was changed, i delete the item from the collection that has binding with itemsource of datagrid and after i insert the same item with new value in the same position, approximately i do this:

Collection.RemoveAt(index);
Collection.Insert(index, Data);

in this way my collection was changed so the datagrid was updated.

After reading your reply i understood that i have implemented INotifyPropertyChanged interface in wrong class, because i've implemented it in the class that contains my collection and not in the business item of my collection...
I can't implement this interface directly to business data of my collection because it is provided from the framework of my company, (i will ask if admin can implement this interface) for now i solved creating my personal business data that contains the name and main business data, then in my personal business data i implemented INotifyPropertyChanged interface and it works!

Thank you so much!

0
Densi
Top achievements
Rank 1
answered on 12 Apr 2016, 09:56 AM

Hello Ivaylo,
thank you for your reply, before your reply, i've tried to implement INotifyPropertyChanged interface but it wasn't working, then i solved my problem through another my class, in this class i simply checked when a value of an item of my collection was changed, then if a value was changed, i delete the item from the collection that has binding with itemsource of datagrid and after i insert the same item with new value in the same position, approximately:

Collection.RemoveAt(index);
Collection.Insert(index, Data);

in this way my collection was changed so the datagrid was updated.

After reading your reply i understood that i have implemented INotifyPropertyChanged interface in wrong class, because i've implemented it in the class that contains my collection and not in the business item of my collection...
I can't implement this interface directly to business data of my collection because it is provided from framework of my company, i will ask if admin can implement this interface, for now i solved creating my personal business data that contains the name and main business data, then in my personal business data i implemented INotifyPropertyChanged interface and it works!

Thank you so much!

0
Densi
Top achievements
Rank 1
answered on 12 Apr 2016, 10:00 AM
Sorry, i mean company where i work, not "my company"...
Tags
DataGrid
Asked by
Densi
Top achievements
Rank 1
Answers by
Densi
Top achievements
Rank 1
Ivaylo Gergov
Telerik team
Share this question
or