Results 1 to 5 of 5

Thread: [2008] Sort Class

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2003
    Location
    Wigan, UK
    Posts
    291

    [2008] Sort Class

    Can anybody show me how you override the sort property of the listbox in a class and the usage of it please ?

    Thanks

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2008] Sort Class

    Here's a link that shows how to do it:

    Custom Sorter

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2003
    Location
    Wigan, UK
    Posts
    291

    Re: [2008] Sort Class

    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.
    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
    Thanks.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2008] Sort 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.

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2008] Sort Class

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width