473,499 Members | 1,724 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

custom sorting of ListBox controls

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?
Nov 22 '05 #1
5 4798
Cor
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
Nov 22 '05 #2
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]
- mv*@spam.guard.caspershouse.com

"Marri Suliez" <ma*@spam.com> wrote in message
news:Xn**********************************@24.168.1 28.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?

Nov 22 '05 #3
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" <ma*@spam.com> wrote in message
news:Xn**********************************@24.168.1 28.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?

Nov 22 '05 #4
Cor
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
Nov 22 '05 #5
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" <ma*@spam.com> wrote in message
news:Xn**********************************@24.168.1 28.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?

Nov 22 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
560
by: Marri Suliez | last post by:
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...
3
2376
by: Alex Stevens | last post by:
I'd already posted this in microsoft.public.dotnet.framework.windowsforms and microsoft.public.dotnet.framework.windowsforms.controls to no avail so apologies for the cross-posting. Hi, I'm...
22
6064
by: James Cane | last post by:
Here's an interesting problem that someone might have an answer to... Some time ago, I wrote a set of utility classes which wrap up the custom row source function needed to add arbitrary items to...
4
6055
by: Paradox | last post by:
Hey, I'm trying to figure out what situations call for the use of a derived form control such as: public class myListBox : System.Windows.Forms.ListBox and what situations call for the use...
3
1552
by: Eric Sabine | last post by:
I've created a custom control (ascx) which contains a tree view, a drop down list, and a listbox. The custom control is included in a web form and at runtime, won't compile (I get the...
3
1856
by: Chris Newby | last post by:
I have a very simple custom control that derives from WebControls.Panel and implements INamingContainer. It appear that controls created as children of my custom control are having ViewState...
0
1073
by: Chris Newby | last post by:
I have a custom control that is essentially implemented as follows: ================================================ public class TestPanel : WebControl, INamingContainer { protected override...
0
3213
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
2
2300
by: tepesco | last post by:
Hi.. I'm trying to create small custom control.. class definition in vb looks like: Imports System Imports System.Web.UI Imports System.Web.UI.WebControls Imports System.Resources Imports...
1
1693
by: jasydnor | last post by:
Hi, New to the forums and have a question. I've only been developing for about five months now so I apologize if this seems oversimplistic....I am writing a program on an idea I had on a whim. ...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.