Update continuously datagrid with data from a list

8 posts, 1 answers
  1. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 05 Apr Link to this post

    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!

  2. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 07 Apr in reply to Densi Link to this post

    Someone can help me?
  3. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 07 Apr Link to this post

    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

  4. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 07 Apr Link to this post

    I also tried dataGridName.UpdateLayout(); but nothing changes.... 
  5. Answer
    Ivaylo Gergov
    Admin
    Ivaylo Gergov avatar
    661 posts

    Posted 11 Apr Link to this post

    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
  6. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 12 Apr in reply to Ivaylo Gergov Link to this post

    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!

  7. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 12 Apr in reply to Ivaylo Gergov Link to this post

    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!

  8. Densi
    Densi avatar
    7 posts
    Member since:
    Mar 2016

    Posted 12 Apr in reply to Densi Link to this post

    Sorry, i mean company where i work, not "my company"...
Back to Top