1

I have DataGridView and DataSource is List. When I'm changing elements property in that List in gridview it is shown previous. When I click on row it changes values. I'm updating list with BackgroundWorker. How update DataGridView at the same time?

hiFI
  • 1,887
  • 3
  • 28
  • 57
Vazgen Torosyan
  • 1,255
  • 1
  • 12
  • 26
  • ObservableCollection in place of List? – SAm Sep 04 '14 at 13:45
  • List<_Input> oldList; public class _Input { public string Title { get; set; } public string Item { get; set; } public double Cost { get; set; } public double FixedPrice { get; set; } public double FloorPrice { get; set; } public string Asin1 { get; set; } public bool Edited { get; set; } } – Vazgen Torosyan Sep 04 '14 at 13:48
  • 1
    can you try, System.Collections.ObjectModel.ObservableCollection<_Input> oldList instead of List<_Input> oldList? – SAm Sep 04 '14 at 13:53
  • I have tried but isn't working. – Vazgen Torosyan Sep 04 '14 at 14:05

2 Answers2

0

You will have to use ObservableCollection combined with INotifyPropertyChanged as ObservableCollection notifies only when items are added or removed but not when they are changed.

ObservableCollection Class

How to Listen to Property Changes of Items of an ObservableCollection

There is also one more similar question on SO that might help you.

Community
  • 1
  • 1
Syed Farjad Zia Zaidi
  • 3,302
  • 4
  • 27
  • 50
0

modified excerpt from msdn

private void RefreshGrid(object dataSource)
{
    yourGridName.Invoke((Action)delegate
    {
        var myCurrencyManager = (CurrencyManager)yourGridName.BindingContext[dataSource];
        myCurrencyManager.Refresh();
    });
}

Call this method whenever your background worker updates the dataSource.

SAm
  • 2,154
  • 28
  • 28