Link to home
Start Free TrialLog in
Avatar of mromeo
mromeo

asked on

Cannot add identical strings in first column of CListCtrl

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;
Avatar of nonubik
nonubik

I reproduced your problem. Seems to be from the LVS_EDITLABELS style. If exclude it from the styles, it will behave normaly.
Avatar of mromeo

ASKER

I tried excluding that style.  That didn't change the result for me.   Did you actually get that to work?
Do not mind the above comment :)
I's from the sorting
Avatar of mromeo

ASKER

It appears to be the LVS_SORTASCENDING style.  Is there any way around this limitation?
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
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.
ASKER CERTIFIED SOLUTION
Avatar of nonubik
nonubik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mromeo

ASKER

Ahhh..I see.  I suppose that makes sense.  Perhaps I should add them all unsorted first and then sort them afterwards.  Thanks.
Avatar of AndyAinscow
No - check the index of the newly added item, then add the subitems to that - it should be returned from the InsertItem