473,772 Members | 2,564 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 DataSourceChang ed 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 4821
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(mydata set.tables(0))
dv.Sort = "myItem ASC"
listbox.datasou rce=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.co m

"Marri Suliez" <ma*@spam.com > wrote in message
news:Xn******** *************** ***********@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 DataSourceChang ed 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.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 DataSourceChang ed 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.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 DataSourceChang ed 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 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...
3
2420
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 writing a usercontrol which displays the typical two listboxes and the ability to move items from one to the other. The listboxes are populated with my custom objects (SwapItem), which simply
22
6135
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 a combo or listbox. It all works nicely and allows me to do things such as sorting by clicking on column headings. Recently, all the machines here were upgraded to Access XP from 97 and I thought it might be time to take advantage of the new...
4
6074
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 of a Custom User Control, generated by adding a new Custom User Control to a project with VS.NET.
3
1562
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 "inaccessible due to its protection level" error) because the NodePopulate event of the treeview is set to private. So I changed it to "protected" and the app compiles fine and runs and properly reacts to the event. Good. The problem is inside that...
3
1869
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 problems. For example, suppose I create a ListBox control as a child of my custom control, attach a SelectedIndexChanged event handler to it, and bind its data in the Page_Load event handler only if the current request is not a post back. I load the...
0
1095
by: Chris Newby | last post by:
I have a custom control that is essentially implemented as follows: ================================================ public class TestPanel : WebControl, INamingContainer { protected override void CreateChildControls() { this.Controls.AddAt( 0, new LiteralControl( "<span id=" + this.ID + ">" ) );
0
3240
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 way... here is my code on how I did it to help anyone starting out get an idea of how to use virtual mode in ..NET 2.0 Imports CrystalDecisions.CrystalReports.Engine Imports CrystalDecisions.Shared
2
2317
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 System.ComponentMode
1
1715
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. It's based on the fact that a store (Wal-Mart) is laid out in a logical manner and you can shop efficiently if your shopping list is in order. What I have are two listboxes, the left one contains all the items I might buy and as you double click on...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10264
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8937
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7461
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.