1
votes

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?

2
ObservableCollection in place of List? - SAm
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
can you try, System.Collections.ObjectModel.ObservableCollection<_Input> oldList instead of List<_Input> oldList? - SAm
ok. Thanks. I will try. - Vazgen Torosyan
I have tried but isn't working. - Vazgen Torosyan

2 Answers

0
votes

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.

0
votes

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.