0
我的模型如下。如何查找BindingList的父級?
public class FItem
{
public FItem()
{
FSubsystems = new BindingList<FSubsystem>();
}
public int RecordId { get; set; }
public string ItemName { get; set; }
public BindingList<FSubsystem> FSubsystems { get; set; }
}
public class FSubsystem
{
public int SubSystemID { get; set; }
public string ItemName { get; set; }
public int YearID { get; set; }
}
代碼:
FItems = new ObservableCollection<MarketRecord.FItem>();
FItems.CollectionChanged += OnUiCollectionChanged;
private void OnUiCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
var addedItem = e.NewItems[0] as MarketRecord.FItem;
if (addedItem != null)
{
addedItem.PropertyChanged += OnColumnModified;
if (addedItem.RecordId == 0)
modifedItems.Add(addedItem);
addedItem.FSubsystems.ListChanged += OnColumnModified;
}
}
}
private void OnColumnModified(object sender, EventArgs e)
{
if (sender.GetType().Name == "FItem")
{
MarketRecord.FItem modifiedItem = (sender as MarketRecord.FItem);
if (!modifedItems.Contains(modifiedItem))
modifedItems.Add(modifiedItem);
}
else
{
// add parent of the binding list (i.e fitem object) add it to modifedItems
// Find parent here
}
}
由於我的代碼告訴我需要找到在OnColumnModified的else子句綁定列表中的父母。我怎樣才能做到這一點 ?