Wrox Programmer Forums
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2004, 04:06 PM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting a Listbox

I'm trying to sort the items in a listbox. So far, I have this Sub:

Code:
Sub SortListbox(ByRef box As ListBox)
        Dim sortedItems As New SortedList
        Dim i As Integer

        For i = 1 To box.Items.Count - 1
            sortedItems.Add(box.Items(i).Text, box.Items(i).Value)
        Next
        box.Items.Clear()
        box.DataSource = sortedItems
        box.DataTextField = "LinkText"
        box.DataValueField = "id"
        box.DataBind()
    End Sub
This greets me with the friendly error:
"DataBinder.Eval: 'System.Collections.DictionaryEntry' does not contain a property with the name LinkText."

Am I on the right track? I think I'm really close.

-Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 20th, 2004, 11:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You can bind a listbox to the SortedList object because it is a collection. I think that the fields that you specify ("LinkText" and "id") aren't the fields you need to bind to. Looking at the MSDN, I think you may want to try to reference it to the "key" field and the "value" field. I don't know if that will work; the SortedList collection isn't as straightforward as some of the other collection classes are.

Sorry I couldn't be more help; hopefully someone else will give you a better answer.

Brian
 
Old February 23rd, 2004, 10:19 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually, Brian, I had persued that avenue, and while I didn't receive an error, the functionality wasn't there.

Here's what I used:
Code:
Sub SortListbox(ByRef box As ListBox)
        Dim sortedItems As New SortedList
        Dim i As Integer

        For i = 1 To box.Items.Count - 1
            sortedItems.Add(box.Items(i).Text, box.Items(i).Value)
        Next
        box.Items.Clear()
        box.DataSource = sortedItems
        box.DataTextField = "key"
        box.DataValueField = "value"
        box.DataBind()
    End Sub


I'm overwriting and not sorting. This needs work...
I'm open to suggestions!

- Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.
 
Old February 23rd, 2004, 10:42 AM
Friend of Wrox
 
Join Date: Oct 2003
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was able to dig up a solution. You can find it at:
http://www.411asp.net/func/content?t...box&id=5881410

I was a bit suprised to have such a simple concept be implemented in such a way. Hopefully Whidbey gets on board with this concept for sorting listboxes!

- Colonel

- - - - - - - - - - - - - - - - - - - - - - -
In God we trust, everything else we test.





Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Sorting listbox in web application SachinMalge ASP.NET 2.0 Basics 3 February 2nd, 2007 08:45 AM
sorting kondapally Crystal Reports 2 January 21st, 2005 10:51 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.