Purples:
I have a master-details gridview, but the data should be refreshed when the source data is changed. I implemented INotifyPropertyChanged interface for the model class. However, when I use the hierarchical gridview, when the binding data is changed, the gridview could NOT always work fine.
The attached is my test program.
The first level is Product, the child level is its orders.
I have a background thread to update the product and orders.
I am using 2017.1.221.40.Trial.
CODE below:
----------------------------------------------------------------------
public partial class RadForm1 : Telerik.WinControls.UI.RadForm
{
BindingList<ProductData> _tradeProdDataList = new BindingList<ProductData>();
public RadForm1()
{
InitializeComponent();
GenenateData();
this.radGridView1.DataSource = _tradeProdDataList;
this.radGridView1.AutoGenerateHierarchy = true;
}
private void GenenateData()
{
for (int i = 0; i < 10; i++)
{
var prod = new ProductData() { ID = i };
_tradeProdDataList.Add(prod);
var list = new List<OrderData>();
for (int j = 0; j < 10; j++)
{
var o = new OrderData() { ProductID = i, OrderName = string.Format("Test-{0}-{1}", i, j) };
list.Add(o);
}
prod.Orders.AddRange(list);
}
}
private void radButton1_Click(object sender, EventArgs e)
{
var t1= Task.Factory.StartNew(new Action(() =>
{
while (true)
{
_tradeProdDataList.ToList().ForEach(p =>
{
p.Quantity = new Random().NextDouble() * 1000.0;
p.Orders.ToList().ForEach(o =>
{
o.LastPx = new Random().NextDouble() * 1000.0;
});
});
}
}));
}
}
public class ProductData : INotifyPropertyChanged
{
public ProductData()
{
Orders = new List<OrderData>();
}
public int ID { get; set; }
private double _Quantity;
public double Quantity { get { return _Quantity; } set { _Quantity = value; NotifyPropertyChanged(); } }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "none passed")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public List<OrderData> Orders
{
get; set;
}
}
public class OrderData : INotifyPropertyChanged
{
public int ProductID { get; set; }
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "none passed")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private string _OrderName; public string OrderName { get { return _OrderName; } set { _OrderName = value; NotifyPropertyChanged(); } }
private double _LastPx;
public double LastPx { get { return _LastPx; } set { if (value != _LastPx) { _LastPx = value; NotifyPropertyChanged("LastPx"); } } }
}