473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Loosing ListView.SubItems on Sorting [#C] Win

Hi everyone,

After reading various posts I'm still scratching my head and unsure of what
approach to take. I have created buttons that upon clicking, the buttons add
an item name (myName) to my ListView (lvBody) and at the same time, also add
subitems(unitPrice);

The problems is that if I don't have sort going on, then all "subitems" are
fine. If I have sorting, then the "subitems" that are being placed above the
last Alpha "subitems" info are being lost, and just the first entry and
lowest entry "subitems are being displayed, sample output ie:

UnSorted

Tuna Sand $7.95
ClubHouse $8.95
Wild Oysters $24.95
BLT $6.95

Sorted

BLT
ClubHouse
Tuna Sand $7.95
Wild Oysters $24.95

--------------------

My syntax is as follows:

this.lvBody.Sorting = SortOrder.Ascending; //Sort ListView in Ascending
Order
string unitPrice = System.String.Format("(0:C)", myPrice);

this.lvBody.BeginUpdate();
this.lvBody.Items.Add(myName);
this.lvBody.Items.[ListViewCounter].SubItems.Add(unitPrice.ToString());
this.lvBody.EndUpdate();

ListViewCounter += 1; //increments counter by 1

Now I'm unsure if I should manually sort the ListView every time an item is
added, ICompare, sort in a Collection, etc, etc. Any and all help is truly
appreciated.

MikeY
May 3 '06 #1
2 2100
> My syntax is as follows:

this.lvBody.Sorting = SortOrder.Ascending; //Sort ListView in Ascending
Order
string unitPrice = System.String.Format("(0:C)", myPrice);

this.lvBody.BeginUpdate();
this.lvBody.Items.Add(myName);
this.lvBody.Items.[ListViewCounter].SubItems.Add(unitPrice.ToString());
this.lvBody.EndUpdate();

ListViewCounter += 1; //increments counter by 1
Just a guess, but I suspect that the problem is in the two lines: this.lvBody.Items.Add(myName);
this.lvBody.Items.[ListViewCounter].SubItems.Add(unitPrice.ToString());


Because the list is sorted, after the item has been added by the first line
it will probably be moved to the correct SORTED position in the Items array,
and thus the second line is referring to the wrong item. Try changing it to:
ListViewItem lvi = this.lvBody.Items.Add(myName);
lvi..SubItems.Add(unitPrice.ToString());

Chris Jobson
May 3 '06 #2
Thanks Chris,

LOL Something so easy that one overlooks sometimes and I've been scratching
my head for the past week or so trying to figure this problem out. I worked
perfectly.

MikeY
"Chris Jobson" <ch**********@btinternet.com> wrote in message
news:eV******************@TK2MSFTNGP02.phx.gbl...
My syntax is as follows:

this.lvBody.Sorting = SortOrder.Ascending; //Sort ListView in Ascending
Order
string unitPrice = System.String.Format("(0:C)", myPrice);

this.lvBody.BeginUpdate();
this.lvBody.Items.Add(myName);
this.lvBody.Items.[ListViewCounter].SubItems.Add(unitPrice.ToString());
this.lvBody.EndUpdate();

ListViewCounter += 1; //increments counter by 1


Just a guess, but I suspect that the problem is in the two lines:
this.lvBody.Items.Add(myName);
this.lvBody.Items.[ListViewCounter].SubItems.Add(unitPrice.ToString());


Because the list is sorted, after the item has been added by the first
line it will probably be moved to the correct SORTED position in the Items
array, and thus the second line is referring to the wrong item. Try
changing it to:
ListViewItem lvi = this.lvBody.Items.Add(myName);
lvi..SubItems.Add(unitPrice.ToString());

Chris Jobson

May 4 '06 #3

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

Similar topics

0
by: rmorvay | last post by:
I have successfully integrated sorting in the listview control with the following code: Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As...
1
by: J_Max | last post by:
Hello, This might be a really easy question, but... I am developing a simple Smart Device application that uses a listview. I have a function that adds a item to the listview - code is below. I...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
1
by: Mamatha | last post by:
Hi I have one application ,that diplays data from database into the listview control.While adding data to the listview i want to display an icon to the leftside of the first column's data.Here...
6
by: Dave | last post by:
VB6 has a SorkKey property that you can setup on the ListView control to tell the ListView what column to use for sorting. In .NET there is a Sort() method and a SortOrder property that you can...
1
by: Joe | last post by:
I set up two columns in listview. I use Add to add items, but how do I access the second column? and add text?
2
by: mrmagoo | last post by:
I'm trying to fill a listview with data. I'm using the example from the help file, but how do I modify this to avoid using images? I want the exact same layout but without images. This procedure...
1
by: samoore33 | last post by:
I found this code on MSDN, and it works great. It creates a ListView dynamically and add items to it and all. It is great. I have changed a few of the column names to suit me. Dim listView1 As...
4
by: rajtalent | last post by:
hi all, I want to sort the colum when clicks the columnheader using vb.net 2005 .But i receive the following error "Error 1 Overload resolution failed because no accessible 'New' accepts...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.