Answer the question
In order to leave comments, you need to log in
Why don't collection events work if the UserControl that owns this collection is a field and not a local variable?
Good afternoon. I have a collection of controls inherited from IList. In the Add method, I call the ReportAdded event
internal class ReportList : IList<PreviewReport>
{
...
public readonly List<PreviewReport> Items;
public ReportList()
{
Items = new List<PreviewReport>();
}
public void Add(PreviewReport previewReport)
{
Items.Add(previewReport);
ReportAdded?.Invoke(previewReport, new EventArgs());
}
....
}
public Folder()
{
InitializeComponent();
Reports = new ReportList();
Reports.ReportAdded += Reports_ReportAdded;
}
private void Reports_ReportAdded(object sender, EventArgs e)
{
//логика
}
for (int i = 0; i < 8; i++)
folder1.Reports.Add(new PreviewReport());
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question