CListCtrl List Style :: MFC

This is a discussion on CListCtrl List Style :: MFC within the Windows Programming forums, part of the Platform Specific Boards category; Hi. I added a simple CListCtrl box with a List style to a dialog box. However, I cannot insert more ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348

    CListCtrl List Style :: MFC

    Hi.

    I added a simple CListCtrl box with a List style to a dialog box. However, I cannot insert more than one item. Another possible problem is that Windows is not drawing the other items. Nonetheless, only one item shows up. Here is an example what how I inserted items.

    Code:
    OnInitDialog(...)
    {
    LVITEM Item;
    Item.mask = LVIF_TEXT;
    Item.state = LVIS_SELECTED;
    Item.stateMask = LVIS_SELECTED;
    Item.cchTextMax = 0;
    Item.iImage = 0;
    Item.lParam = 0;
    Item.iSubItem = 0;
    Item.pszText = TEXT("November");
    
    // I would like to insert ten items in the list box.
    
    for (unsigned i = 0; i < 10; ++i)
       theListBox.InsertItem(&Item);
    After the insertion above, only one line of "Novermber" will show up in the CListCtrl box.

    I have worked with CListCtrl boxes using Report Style. I have not had this problem. I would like to know why does it ignore all new items except the first line?

    Thanks,
    Kuphryn

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Try explicitly setting the iItem and iSubItem of your LVITEM to set each of the 10 items within your loop.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks everyone.

    I decided to go back to the same solution I have been using on othe projects: Report style. It works perfect.

    Kuphryn

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,859
    Try
    Code:
    Item.mask=LVIF_TEXT | LVIF_PARAM;
    
    for (unsigned i = 0; i < 10; ++i)
    {
            Item.iItem=i;
            Item.lParam=i;
            theListBox.InsertItem(&Item);
    }
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Okay. Thanks.

    Your solution is unique in that it increments the lParam value. I will consider it.

    Kuphryn

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help! Placement of nodes in a Linked List
    By lostmyshadow in forum C Programming
    Replies: 6
    Last Post: 12-17-2007, 12:21 PM
  2. deleting a node in linked list
    By BoneXXX in forum C Programming
    Replies: 18
    Last Post: 12-17-2007, 11:30 AM
  3. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  4. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21