CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2006
    Posts
    23

    CListCtrl InsertItem Error

    I have a structure of the following
    Code:
    typedef struct
    {
    	CString m_csKeyPressed;
    	CString m_csCircleColor;
    	CString m_csMouseX;
    	CString m_csMouseY;
    }CircleParameters;
    All the data members in the struct are the item and subitems that will be entered subsequently.

    I want to be able to insert the item using

    Code:
    CircleParameters param;
    param.m_csKeyPressed = "Test";
    param.m_csCircleColor= "Test";
    param.m_csMouseX= "Test";
    param.m_csMouseY= "Test";
    
    m_ListCtrl.InsertItem((LVITEM*)&param);
    but it does not work. instead, if I do something like

    Code:
    m_ListCtrl.InsertItem(m_nCircleCount,param.m_csKeyPressed);
    m_ListCtrl.SetItemText(m_nCircleCount,1,param.m_csCircleColor);
    m_ListCtrl.SetItemText(m_nCircleCount,2,param.m_csMouseX);
    m_ListCtrl.SetItemText(m_nCircleCount,3,param.m_csMouseY);
    It works.

    What am I doing wrong here?

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CListCtrl InsertItem Error

    The following won't work because param isn't an LVITEM pointer.
    Code:
    CircleParameters param;
    param.m_csKeyPressed = "Test";
    param.m_csCircleColor= "Test";
    param.m_csMouseX= "Test";
    param.m_csMouseY= "Test";
    
    m_ListCtrl.InsertItem((LVITEM*)&param);
    The way you are doing it is fine or you can use a virtual list control and handle the OnDispInfo message.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured