Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Cannot add identical strings in first column of CListCtrl

Posted on 2004-09-02
9
Medium Priority
?
211 Views
Last Modified: 2013-11-20
Hi.  I add two rows of text to a list control (with report view) where the first column has the same string in it.  For example:

   listCtrl.InsertItem(0, "MyString");
   listCtrl.SetItemText(0, 1, "Row0Col1");
   listCtrl.SetItemText(0, 2, "Row0Col2");

   listCtrl.InsertItem(1, "MyString");
   listCtrl.SetItemText(1, 1, "Row1Col1");
   listCtrl.SetItemText(1, 2, "Row1Col2");

The result is that the first row contains the column 1 text ("MyString"), but columns 2 and 3 are blank.  Row 2 contains everything that I would expect it to contain.
Ie.

Row1:       My String  |                   |
Row2:       My String  |  Row1Col1   |   Row1Col2

If I change the column 1 strings so that are differnt, then both rows have all the strings I would expect (below).  Do the strings in column 0 have to be unique?  What's going on here?

Row1:       My String Row 1 |  Row1Col1   |   Row1Col2
Row2:       My String Row 2 |  Row1Col1   |   Row1Col2

Also, the ListView is created with the following flags:

style &= ~LVS_TYPEMASK;
style |= LVS_REPORT;
style |= LVS_EDITLABELS;
style |= LVS_SORTASCENDING;
style |= LVS_SINGLESEL;
0
Comment
Question by:mromeo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 16

Expert Comment

by:nonubik
ID: 11964148
I reproduced your problem. Seems to be from the LVS_EDITLABELS style. If exclude it from the styles, it will behave normaly.
0
 

Author Comment

by:mromeo
ID: 11964196
I tried excluding that style.  That didn't change the result for me.   Did you actually get that to work?
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11964210
Do not mind the above comment :)
I's from the sorting
0
Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

 

Author Comment

by:mromeo
ID: 11964227
It appears to be the LVS_SORTASCENDING style.  Is there any way around this limitation?
0
 
LVL 16

Expert Comment

by:nonubik
ID: 11964236
It's a problem sorting the items in a list control.
If you do not set a sorting style, will work...
I'll try digging deeper
0
 
LVL 11

Expert Comment

by:KurtVon
ID: 11964292
I think nonubik is explaining that the insert item position is ignored if the list control is sorted, so you are actually changing the first item's row with your second set of SetItemText statements.  Try using the return value from InsertItem as the row number instead.
0
 
LVL 16

Accepted Solution

by:
nonubik earned 600 total points
ID: 11964310
Ok, I got it. It's quite simple :)

When you insert the second  item, because it is the same with the first, the sorting algorithm will place it first.
But you set the item text for the second.... So the first one (the one you just inserted) has no subitem texts.

You should do:

int iIdx = listCtrl.InsertItem(1, "MyString");
   listCtrl.SetItemText(iIdx, 1, "Row1Col1");
   listCtrl.SetItemText(iIdx, 2, "Row1Col2");
0
 

Author Comment

by:mromeo
ID: 11964322
Ahhh..I see.  I suppose that makes sense.  Perhaps I should add them all unsorted first and then sort them afterwards.  Thanks.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 11970520
No - check the index of the newly added item, then add the subitems to that - it should be returned from the InsertItem
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Suggested Courses

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question