Solved

CListCtrl not showing all sub items

Posted on 2000-04-12
7
194 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
Comment Utility
Did you add all columns req?
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
Please post some code...
0
 

Author Comment

by:ch52jb
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Accepted Solution

by:
GregoryG earned 100 total points
Comment Utility
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
Comment Utility
What is the output?
Are whoule items missing? or just sum items?
0
 
LVL 3

Expert Comment

by:V_Bapat
Comment Utility
>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
Comment Utility
I had the list set to sort, hence my problems.  Cheers, enjoy the points!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This video discusses moving either the default database or any database to a new volume.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now