[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

CListCtrl not showing all sub items

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
ch52jb
Asked:
ch52jb
1 Solution
 
shaigCommented:
Did you add all columns req?
0
 
ZoppoCommented:
Please post some code...
0
 
ch52jbAuthor Commented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
GregoryGCommented:
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
 
shaigCommented:
What is the output?
Are whoule items missing? or just sum items?
0
 
V_BapatCommented:
>When I add items to the list only a few of the sub items are added...

Can you elaborate on that?
0
 
ch52jbAuthor Commented:
I had the list set to sort, hence my problems.  Cheers, enjoy the points!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now