We help IT Professionals succeed at work.

Probs with CListCtrl in report view

DevonportA1
DevonportA1 asked
on
How do I insert text into the columns of a list control which is in report view.

I'm trying this function:
int InsertItem( const LVITEM* pItem);

LVITEM is the following struct which "specifies or receives the attributes of a list view item".

typedef struct _LVITEM {
    UNIT mask;
    int iItem;
    int iSubItem;
    UNIT state;
    UNIT stateMask;
    LPTSTR pszText;
    int cchTextMax;
    int iImage;
    LPARAM lParam;
#if (_WIN32_IE>= 0x0300)
    int iIndent;
#endif
} LVITEM, FAR *LPLVITEM;

Firstly, is this the right way to go about inserting text into the columns? Does each piece of text have one of these structures associated with it?

Secondly, when I try and compile this I get the following error on the line with UNIT mask:

"error C2059 : syntax error : 'constant'  

do you know what causes this?
Comment
Watch Question

BRONZE EXPERT

Commented:
Hi DevonportA1,

InsertItem is the correct way to insert text of first column, to insert text to further
columns you'll have to use CListCtrl::SetItemText(). Be aware that you have to
first insert the columns with CListCtrl::InsertColumn().

Maybe you'll find some other implementations of CListCtrl::InsertItem() easier to
use then the shown one.

About the error: could you post the exact code where this error occurs?

hope that helps,

ZOPPO

Sr Program Manager
Commented:
Hi,

U can use the InsertItem() function in a simple way if u r inserting simple text. The InsertItem() will insert the text in first column along with inserting the row into the list control. Say U have 3 columns in a list control, then u can insert the items as

//First row items
m_ctrlList.InsertItem(0, "Row1Col1");
m_ctrlList.SetItemText(0, 1, "Row1Col2");
m_ctrlList.SetItemText(0, 2, "Row1Col3");

//Second row items
m_ctrlList.InsertItem(1, "Row2Col1");
m_ctrlList.SetItemText(1, 1, "Row2Col2");
m_ctrlList.SetItemText(1, 2, "Row2Col3");

U need not use LVITEM structure always to insert into list control.

Try it out.
VinExpert

Explore More ContentExplore courses, solutions, and other research materials related to this topic.