CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2008
    Posts
    7

    [RESOLVED] First items in Listbox C#

    I have a listbox of countries populated from a datasource and sorted by country name.
    I would like to have my two mostly used countries, the "US" and "Canada" at the top of the list.
    Is there an easy way to do this.
    Thanks,
    Pierre

  2. #2
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: First items in Listbox C#

    In the table, add one more column - say priority. Set it to 2 for US, 1 for canada, and 0 for all others.
    Sort by priority and then by name!
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  3. #3
    Join Date
    Feb 2008
    Posts
    7

    Re: First items in Listbox C#

    That's work fine, was still hoping to find a way to do it within the list box without changing the table.

  4. #4
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: [RESOLVED] First items in Listbox C#

    Then code it yourself! Append US and Canada as first two entries, and retrieve other countries from table. But in that case you would lose automatic data binding.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: [RESOLVED] First items in Listbox C#

    Yes, as Ajay alludes to you can create your own Comparer class that can selectively push those two entries to the top and sort the rest by alphabet or however you like.
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

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

Featured