in Education by
I want to add an event to the List generic class in C# in order to handle changing items of list in case that a new item is added or removed. I create class and inherit it from List class. Since the Add, Insert, and Remove methods of this class can't be overrode, I define new Add, Insert, and Remove methods by new keyword and call the parent methods and then raise my event. I used this class as a property in an User Control. In design mode when I change the collection with provided GUI in .net development studio, the event does not work. How can I solve this problem? Here is an example of defining such a class public class SelectorItemCollection : List { public new void Add(SelectorItem Item) { //Call parent method base.Add(Item); //Raise changing event this.OnCollectionChanged(); } } I defined a property in my user control class like this: [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public SelectorItemCollection Items { get; } My desired state that when I change the items in this dialog, I want to raise a changing event from collection class. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Don't reinvent the wheel, use a collection class that already supports such notifications, like ObservableCollection or BindingList (if you're using data binding in WPF, use the former; in Windows Forms, use the latter). If you want to implement your own, don't inherit from List, because it was not designed for inheritance. Instead, you could use Collection as your base class.

Related questions

0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 9, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 7, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
    I want to add an event to the List generic class in C# in order to handle changing items of list ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 5, 2022 in Education by JackTerrance
0 votes
0 votes
    I've got a Sharepoint WebPart which loads a custom User Control. The user control contains a Repeater which ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    I've got a Sharepoint WebPart which loads a custom User Control. The user control contains a Repeater which ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I've got a Sharepoint WebPart which loads a custom User Control. The user control contains a Repeater which ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I've got a Sharepoint WebPart which loads a custom User Control. The user control contains a Repeater which ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    Which is the method used to add an event listener? (a) addEventListener() (b) addListener() (c) ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 23, 2021 in Education by JackTerrance
0 votes
    I saw an article on creating Excel UDFs in VSTO managed code, using VBA: http://blogs.msdn.com/ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 19, 2022 in Education by JackTerrance
0 votes
    Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
...