开发者

Overloading list adding method

I'm writing a basic app based on visual components (button, textbox) and a List of custom class type. My goal is to make textbox auto-update each time I add an element to a list. Is开发者_StackOverflow it possible to overload List.Add() method to append also text into a textbox?


try to use the BindingList class

in WPF you can use the ObservableCollection class for binding


The List<T> class is designed for performance, not for inheritance, and most of its methods are not virtual, so you can't override them. Instead, you can inherit from Collection<T>, which is designed for inheritance, and override the InsertItem method.

But anyway, I don't think a collection class is the right place to update a TextBox... Instead, you should use a collection class that raises events when it's modified (like BindingList<T> or ObservableCollection<T>), and react to the events to update the TextBox

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜