PC Review


Reply
Thread Tools Rate Thread

custom sorting of ListBox controls

 
 
Marri Suliez
Guest
Posts: n/a
 
      26th Jan 2004
Has anyone found some documentation on how to properly subclass a ListBox
control and provide custom sorting (when the list items come from a
DataSource)?

The only way I can figure out how to do this is by sorting an array of some
sort and then setting the DataSource. I don't like this because it fires
the DataSourceChanged event.

What I really want to do is get access to the underlying list items, sort
them, and then have the control refresh itself. I already have access to
the underlying list items since I have set the DataSource myself. But
changing the order of the items in the DataSource does not appear to result
in the items in the control being resorted.

Any suggestions?
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      26th Jan 2004
Hi,

Have a look at the dataview
Basicly it is not more thatn

I do not know if you use VB or C# so some things in VB
\\\
dim dv as new dataview(mydataset.tables(0))
dv.Sort = "myItem ASC"
listbox.datasource=dv
and the rest as you did it.
///

I hope this helps?

Cor


 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      26th Jan 2004
Marri,

There are two kinds of sorts going on here. The first is the Sort that
the ListBox class calls. Basically, in order to use that, you will have to
clear the collection and re-add the items in the order that you want them to
be sorted in.

The other kind is the sort order that the collection has when bounded to
a data set. You can change the order in the underlying list items, but that
doesn't matter. The reason is because when bound to a data table, you are
binding to the default view on the table. Change the sort order on the
view, and you should notice that the items in the list are listed separately
(you might have to rebind).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Marri Suliez" <(E-Mail Removed)> wrote in message
news:Xns947C7115FF893MarriSuliezMarriSuli@24.168.128.86...
> Has anyone found some documentation on how to properly subclass a ListBox
> control and provide custom sorting (when the list items come from a
> DataSource)?
>
> The only way I can figure out how to do this is by sorting an array of

some
> sort and then setting the DataSource. I don't like this because it fires
> the DataSourceChanged event.
>
> What I really want to do is get access to the underlying list items, sort
> them, and then have the control refresh itself. I already have access to
> the underlying list items since I have set the DataSource myself. But
> changing the order of the items in the DataSource does not appear to

result
> in the items in the control being resorted.
>
> Any suggestions?



 
Reply With Quote
 
John Timney \(Microsoft MVP\)
Guest
Posts: n/a
 
      26th Jan 2004
read this - might help you

http://www.dotnetbips.com/displayarticle.aspx?id=232

--
Regards

John Timney
Microsoft Regional Director
Microsoft MVP
----------------------------------------------------------------------------
------------------------------------
<blatant plug>
Professional .NET for Java Developers with C#- ISBN: 1-861007-91-4
Professional Windows Forms - ISBN: 1861005547
Professional JSP 2nd Edition - ISBN: 1861004958
Professional JSP - ISBN:
1861003625
Beginning JSP Web Development - ISBN: 1861002092
</blatant plug>
----------------------------------------------------------------------------
------------------------------------

"Marri Suliez" <(E-Mail Removed)> wrote in message
news:Xns947C7115FF893MarriSuliezMarriSuli@24.168.128.86...
> Has anyone found some documentation on how to properly subclass a ListBox
> control and provide custom sorting (when the list items come from a
> DataSource)?
>
> The only way I can figure out how to do this is by sorting an array of

some
> sort and then setting the DataSource. I don't like this because it fires
> the DataSourceChanged event.
>
> What I really want to do is get access to the underlying list items, sort
> them, and then have the control refresh itself. I already have access to
> the underlying list items since I have set the DataSource myself. But
> changing the order of the items in the DataSource does not appear to

result
> in the items in the control being resorted.
>
> Any suggestions?



 
Reply With Quote
 
Cor
Guest
Posts: n/a
 
      26th Jan 2004
Hi John,

Sorry, this I do not understand.

It is about a listbox the OP is talking about.

He told he knows about a datasource.

Why he needs to make an extra class for this while the dataview is full
suported in the framework.?

And the dataview is very easy to use.

But maybe there is a reason and than I gladly like to know that.

Cor


 
Reply With Quote
 
Justin Rogers
Guest
Posts: n/a
 
      27th Jan 2004
You can override the Sort method in a derived class to provide custom sorting.


--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Marri Suliez" <(E-Mail Removed)> wrote in message
news:Xns947C7115FF893MarriSuliezMarriSuli@24.168.128.86...
> Has anyone found some documentation on how to properly subclass a ListBox
> control and provide custom sorting (when the list items come from a
> DataSource)?
>
> The only way I can figure out how to do this is by sorting an array of some
> sort and then setting the DataSource. I don't like this because it fires
> the DataSourceChanged event.
>
> What I really want to do is get access to the underlying list items, sort
> them, and then have the control refresh itself. I already have access to
> the underlying list items since I have set the DataSource myself. But
> changing the order of the items in the DataSource does not appear to result
> in the items in the control being resorted.
>
> Any suggestions?



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Make ListBox multiline in Custom ListBox Soren-a Microsoft Dot NET Compact Framework 0 25th Nov 2004 02:09 PM
custom sorting of ListBox controls Marri Suliez Microsoft Dot NET 5 27th Jan 2004 05:54 AM
custom sorting of ListBox controls Marri Suliez Microsoft Dot NET Framework Forms 0 26th Jan 2004 04:07 PM
custom sorting of ListBox controls Marri Suliez Microsoft C# .NET 0 26th Jan 2004 04:07 PM
Sorting ListBox results or transposing ListBox values to other cells for sorting Rob Microsoft Excel Programming 1 9th Jul 2003 04:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:41 AM.