Can anybody show me how you override the sort property of the listbox in a class and the usage of it please ?
Thanks
Printable View
Can anybody show me how you override the sort property of the listbox in a class and the usage of it please ?
Thanks
Here's a link that shows how to do it:
Custom Sorter
Thanks, i can see how it works but i am after the code and usage of overriding a property of the listbox. I have this but how do you use it with Listbox1 on the form.
Thanks.Code:Public Class MySort
Inherits ListBox
Protected Overrides Sub Sort()
'what is this mybase.sort ?
MyBase.Sort()
'Im thinking the code for the descending sort goes here
End Sub
End Class
To start, you'll need to create a UserControl for the MySort object, remove the Listbox1 and replace it with a MySort object. Or you might be able to create the MySort object in a method, do all the sorting stuff and then go ListBox1 = CType(mysort_object_you_created, ListBox) - not sure if that would work or not, but I think it would.
For the override Sort method ,when you override a method, the first thing it does is call the base method that gets overriden. I'm not sure if this can be removed or not, but I think it throws an error if you try. After that, you'd put in the code for your custom sorting.
Have you read the documentation for the ListBox.Sort method? It provides a code example.
When overriding methods you often call the overridden base member. This gives you the default implementation of the method, which you can then customise by adding more code. In this case you don't want the default implementation though, so don't call the overridden base member.