473,729 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Bug with listview using custom ListViewSorter

I am trying to create a custom listviewsorter by implementing IComparer. My
listview has check boxes and the purpose is to move checked item to top of
list. They all will be sorted ascendingly. It throws error "-1 is not a
valid index" when the sorting is done with listview. I have no problem using
the same custom sorter for an arraylist of listviewitems. A bug in listview
control? Any suggestion?

Thanks,
-sorpor

Here is the code for the comparer:

internal class listviewsorter: IComparer

{

#region IComparer Members

public int Compare(object x, object y)

{

int result = 0;

ListViewItem itmX = (ListViewItem)x ;

ListViewItem itmY = (ListViewItem)y ;
if (itmX.Checked == itmY.Checked)

result = String.Compare( itmX.Text, itmY.Text);

else

{

System.Diagnost ics.Trace.Write Line("Bool");

result = itmY.Checked.Co mpareTo(itmX.Ch ecked); //checked < not checked

}

return result;

}

#endregion

}

Works fine with ArrayList sorting:

ArrayList testItms = new ArrayList();

ListViewItem a = new ListViewItem("A ");

ListViewItem b = new ListViewItem("B ");

ListViewItem c = new ListViewItem("C ");

c.Checked = true;

testItms.Add(b) ;

testItms.Add(a) ;

testItms.Add(c) ;

foreach(ListVie wItem itm in testItms) //b a c

{

System.Diagnost ics.Trace.Write Line(itm.Text);

}

testItms.Sort(n ew listviewsorter( ));

foreach(ListVie wItem itm in testItms) //c a b

{

System.Diagnost ics.Trace.Write Line(itm.Text);

}
Nov 17 '05 #1
0 1643

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

Similar topics

1
5965
by: Welie | last post by:
Hi all- I am using a listview (MSComctlLib.ListViewCtrl.2)on an Access form. Actually there are six listviews on the form. I need to do the same thing to all six forms so I have the loop below. I would like to assign each control to a listview object, however I get a type mismatch. Further investigation reveals that the type of the control is "Custom Control" and not a listview. I would like to be able to work with real control object's...
1
3447
by: newbie | last post by:
Hello, I maybe asking too much in a single posting, but here it goes: I building a windows form that mimic's the Outlook XP GUI. Its a three pane form that will allow a user to view and edit records in a database. A Treeview in the left pane, a Listview in the TopRight Pane, and a PropertyGrid in the BottomRight; The Treeview will allow the user to select an "Entity" to view, the listview will display a list of instances of
7
6448
by: Dave Y | last post by:
I am a newbie to C# and am having trouble trying to override a ListView property method. I have created a new class derived from the Forms.Listview and I cannot figure out the syntax to override ListView.Items.Add(), . I see that it is a virtual method so it should be easy to do. If anyone can help I would appreciate it greatly. I can do what I need to do in a different way this would just make everything significantly cleaner and eaasier...
1
2891
by: redneon | last post by:
Is it possible to get the Handle property for a particular cell in a ListView? I'm wanting to turn a cell into a progress bar rather than just displaying text. If it's possible to get the Handle I can just do Graphics.FromHwnd(listView1.Handle); and then use FillRectangle to display the progress bar. Any ideas? Darrell
5
5847
by: ToddH | last post by:
I know the following code is C#. I'm a vb programmer trying to learn a new language. I posted this in the c# group but never got a response. You guys seem to know alot about all languages and have all the answers, so here it is.. I'm trying to create a custom listview that uses custom listviewitems. The listviewitems persist just fine in design mode. However, when I build the solution, the listview item doesn't show up. I've run some tests,...
5
2519
by: David Gouge | last post by:
Hi all, Hope this is a simple one for you but i seem to be having a bit of a mental block. I have an inherited ListView (NewListView) class and an inherited ListViewItem (NewListViewItem) class. How do i get my NewListView class to accept NewListViewItems into and return NewListViewItems from the Items collection.
3
2394
by: Michael.Suarez | last post by:
Is it me, or does it seem like they put no effort into creating the listview control in .Net. listview. A few gripes I have with .Net listview that aren't present in vb6: -Inability to set tooltiptext of subitems (without the use of a very inconveniant work around). -Inability to display images in subitems (without using the windows api
7
5116
by: =?Utf-8?B?YnJhaW5mdWVsbWVkaWE=?= | last post by:
Can anyone point me in the direction of creating a custom listview item? I guess the other question then - is this possible? I want to create a list of listview items comprised each comprised of text and a set of textboxes.
3
4636
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2 for C# windows application. One of my column on the Listview control has numericstring. Other columns are sorting correctly except this one. It seems to be sorting the 1st numeric char at the beging of the string. How do I resolve this problem? Thank you? -- Thanks.
0
8917
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8761
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
9426
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...
1
6722
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...
0
6022
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
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
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.