2014-09-04 57 views
1

我有DataGridView和数据源是列表。当我在gridview中更改该列表中的元素属性时,它会显示在前面。当我点击行时,它会更改值。我正在使用BackgroundWorker更新列表。如何在同一时间更新DataGridView?DataGridView不更新当我更改数据源

+0

ObservableCollection代替List? – SAm 2014-09-04 13:45:16

+0

List <_Input> oldList; public class _Input { public string Title {get;组; } public string Item {get;组; } public double Cost {get;组; } public double FixedPrice {get;组; } public double FloorPrice {get;组; } 公共字符串Asin1 {get;组; } public bool Edited {get;组; } } – 2014-09-04 13:48:27

+1

你可以试试,System.Collections.ObjectModel.ObservableCollection <_Input> oldList而不是列表<_Input> oldList? – SAm 2014-09-04 13:53:47

回答

0

修改摘自msdn

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

调用此方法时,您的后台工作更新数据源。