CListCtrl item and sub-item confusion 
Author Message
 CListCtrl item and sub-item confusion

Hi,

I am using a CListCtrl control for the first time now.
I have selected the report mode because I want to show a list
of items with specific details in the 2nd and 3rd column.
Creating the columns seems fine but I cannot insert an item
in ANY other column than the first one. I have read the documentation
at least a 1000 times but it seems I am a bit stupid.....:-(

Here's my code :

BOOL Editor::OnInitDialog()
{
        CDialog::OnInitDialog();

        // Create 3 columns
        LV_COLUMN lvcolumn;
        lvcolumn.mask = LVCF_SUBITEM | LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
        lvcolumn.fmt = LVCFMT_LEFT;
        lvcolumn.cx = 100;
        lvcolumn.pszText = "Description";
        lvcolumn.iSubItem = -1;
        m_list.InsertColumn(0,&lvcolumn);
        lvcolumn.pszText = "Status";
        lvcolumn.iSubItem = 1;
        m_list.InsertColumn(1,&lvcolumn);
        lvcolumn.pszText = "Time";
        lvcolumn.iSubItem = 2;
        m_list.InsertColumn(2,&lvcolumn);

        // Insert items in columns
        m_list.InsertItem(0,"Try one");      
        m_list.InsertItem(1,"Try two");      
        m_list.InsertItem(2,"Try three");    
        LV_ITEM lvitem;
        lvitem.mask = LVIF_TEXT;
        lvitem.pszText = "A sub item";
        lvitem.iItem = 1;
        lvitem.iSubItem = 2;
        lvitem.cchTextMax = strlen(lvitem.pszText);
        if(m_list.InsertItem(&lvitem)==-1)
                AfxMessageBox("no");  

        return TRUE;  // return TRUE unless you set the focus to a control
                      // EXCEPTION: OCX Property Pages should return FALSE

Quote:
}

I would expect "A sub item" to be in the column marked "Time" (because
the index is defined 2 in the column creation) next to "Try two".
But the InsertItem keeps returning -1 !!!

Any help or working example code ?

Any help is appreciated,

Regards




Tue, 23 Jan 2001 03:00:00 GMT  
 CListCtrl item and sub-item confusion
It's a simple, but confusing matter. First you insert an item in the first
column. Since you've already _inserted_ the item, you can't call InsertItem
again for the same row. You have to use the CListCtrl::SetItem() function to
add the next columns.

So, the last part of your code would look like this:

 LV_ITEM lvitem;
 lvitem.mask = LVIF_TEXT;
 lvitem.pszText = "A sub item";
 lvitem.iItem = 1;
 lvitem.iSubItem = 2;
 lvitem.cchTextMax = strlen(lvitem.pszText);
 m_list.SetItem (&lvitem);

Tomas Restrepo

http://www.geocities.com/SiliconValley/Heights/3401

Quote:

>Hi,

>I am using a CListCtrl control for the first time now.
>I have selected the report mode because I want to show a list
>of items with specific details in the 2nd and 3rd column.
>Creating the columns seems fine but I cannot insert an item
>in ANY other column than the first one. I have read the documentation
>at least a 1000 times but it seems I am a bit stupid.....:-(



Wed, 24 Jan 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Can I highlight some word of CListCtrl 's item or subitem (jchen)

2. CListCtrl : Image problem in items and subitems

3. How to set the color of a single (Sub)item in a clistctrl

4. Find out what (sub)item has focus in CListCtrl

5. CListCtrl subitems don't follow item sort

6. CListCtrl : I can't see the sub items

7. CListCtrl, only last Item shows all subItems

8. CListCtrl (list Controls) Selecting Items & subitems

9. CListCtrl: How can I in place edit a subitem of a list ctrl item

10. Images in Sub Items in CListCtrl

11. CListCtrl: Inserting an item as the first item in a list of subitems?

12. CListCtrl :Maximum number of items in CListCtrl

 

 
Powered by phpBB® Forum Software