Datagrid and collectionView

Aug 6, 2009 at 9:25 AM



I am trying to make a "global refresh" of my datagrid and not to refresh particular elements (datagrid.Items.Refresh()).

As a first approach I tried to put my collection in a collectionView and then set the the itemsSource of my dataGrid to the collectionView (the code is below).

The code compiles, the lines appear on the dataGrid but I cannot see the values. Can someone explains me why?

Is there a better way to make a global refresh?




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;
using System.Timers;

namespace DGRefresh
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
        private List<Trade> _ListOfTrade = new List<Trade>();
        private CollectionView collectionView;

        public Window1()


            collectionView = new CollectionView(_ListOfTrade);

            dataGrid1.ItemsSource = collectionView;

        void EditListOfTrade()
            for (int i = 0; i < 20; i++)
                Trade trade = new Trade();

    class Trade
        private Random random = new Random();

        public double Field1 { get { return random.NextDouble(); } }
        public double Field2 { get { return random.NextDouble(); } }
        public double Field3 { get { return random.NextDouble(); } }

Aug 14, 2009 at 12:38 PM

Try making it a ListCollectionView instead.  Also, in Trade, you probably want to implement INotifyPropertyChanged.

Sep 1, 2009 at 2:46 PM

Thanks, it's working!