Solved

CListCtrl not showing all sub items

Posted on 2000-04-12
7
197 Views
Last Modified: 2013-11-20
I have a list control on a dialog.  I'm using the CListCtrlEx class from the VC++ samples.  When I add items to the list only a few of the sub items are added, even though the code to add them is in a loop, so the same code is used each time.  Any ideas why and how I can get round it?

Jim
0
Comment
Question by:ch52jb
7 Comments
 
LVL 3

Expert Comment

by:shaig
ID: 2707511
Did you add all columns req?
0
 
LVL 31

Expert Comment

by:Zoppo
ID: 2707530
Please post some code...
0
 

Author Comment

by:ch52jb
ID: 2707670
The code for the list control is

/////////////////////////////////////////////////////////////////////////////
// CListCtrlEx

BOOL CListCtrlEx::AddColumn(LPCTSTR strItem,int nItem,int nSubItem,int nMask,int nFmt)
{
      LV_COLUMN lvc;
      lvc.mask = nMask;
      lvc.fmt = nFmt;
      lvc.pszText = (LPTSTR) strItem;
      lvc.cx = GetStringWidth(lvc.pszText) + 15;
      if(nMask & LVCF_SUBITEM){
            if(nSubItem != -1)
                  lvc.iSubItem = nSubItem;
            else
                  lvc.iSubItem = nItem;
      }
      return InsertColumn(nItem,&lvc);
}

BOOL CListCtrlEx::AddItem(int nItem,int nSubItem,LPCTSTR strItem,int nImageIndex)
{
      LV_ITEM lvItem;
      lvItem.mask = LVIF_TEXT;
      lvItem.iItem = nItem;
      lvItem.iSubItem = nSubItem;
      lvItem.pszText = (LPTSTR) strItem;
      if(nImageIndex != -1){
            lvItem.mask |= LVIF_IMAGE;
            lvItem.iImage |= LVIF_IMAGE;
      }
      if(nSubItem == 0)
            return InsertItem(&lvItem);
      return SetItem(&lvItem);
}

I'm calling it using:

m_List.AddColumn("Word", 0);
m_List.AddColumn("Score", 1);

for(int nCount = 0; nCount < 10; ++nCount)
{
 m_List.AddItem(nCount, 0, MyString1);
 m_List.AddItem(nCount, 1, MyString2);
}
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Accepted Solution

by:
GregoryG earned 100 total points
ID: 2707874
According you code you should see 10
Row with one item and one subitem.
Like this:
"Word"      "Score"
MyString1   MyString2
.....................
MyString1   MyString2
If it what you see but not what you want you should change your code. Please explain what you want in that case.
In case that it is what you want but not what you see check if you list control is sorted. If so you should correct your code like this:
int index;
for(int nCount = 0; nCount < 0;++nCount)
{
 index = m_List.AddItem(nCount, 0, MyString1);
 m_List.AddItem(index, 1, MyString2);
}
Because if you have sorted ListCtrl item will be inserted not into nCount position and InsertItem(&lvItem); will return real row of inserted item.
As whole I'll recommend use code like above and you never need to worry if you have sorted List or not.
0
 
LVL 3

Expert Comment

by:shaig
ID: 2708055
What is the output?
Are whoule items missing? or just sum items?
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2708173
>When I add items to the list only a few of the sub items are added...

Can you elaborate on that?
0
 

Author Comment

by:ch52jb
ID: 2708208
I had the list set to sort, hence my problems.  Cheers, enjoy the points!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

Suggested Solutions

Title # Comments Views Activity
Prevent this page from creating additional dialogs. 3 625
wordcount challenge 11 134
Thin secure Windows 10 5 102
unix example issues 18 100
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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