C#'s ListBox doesn't see my overrided Sort() method

烈酒焚心 提交于 2019-12-08 03:20:29

If you call your Sort, it could be necessary to cast your ListBox to your custom ListBox type (if it is in the base type) to use your specified Sort method.

((MyListBox)myList).Sort();

you must use your overriden ListBox with its correct type, I mean use it as MyListBox and not as ListBox. Don't be afraid that you need to implement all the other methods, you're overriding an existing class and not an interface. you can use all the needed base methods.

If I understand this correctly myListBox1 is of type ListBox not of type MyListBox which is why your Sort isn't being called.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!