Click here to Skip to main content
16,018,525 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem:

I am inserting the values in CListCtrl with
C++
int iItem = m_listModules.InsertItem(9999, csTmp);

//where csTemp is 45.

//using LVN_INSERTITEM which takes it to the function Func1() which has

NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
   
    onInsertItem(pNMListView->iItem, &m_listModules)

onInsertItem(int iItem, CListCtrl *pListCtrl)
{
     CString csRunFile;
    long ldataitem = long(pListCtrl->GetItemData(iItem));

}

This is the flow of code

Now in ldataitem i m getting 0 as a return where as i am inserting 45.

please help

Thanks in advance..
Posted
Updated 29-Aug-11 4:59am
v2

You should be using the GetItem[^] function.

The function GetItemData[^] returns the 32-bit application-specific value associated with the specified item. You have set no such value in the code you shown.

Answer to OP comment:

You need to specify which items information you want to retrieve, this is done in the LVITEM structure you pass to the GetItem function.
Look at the LVITEM[^] documentation.

You can use the following code:
C++
onInsertItem( int iItem, CListCtrl* pListCtrl )
{
	LVITEM plvItem;
	long lDataItem = 0;

	plvItem.mask = LVIF_TEXT;
	plvItem.iItem = iItem;
	if( pListCtrl != NULL && pListCtrl->GetItem( &plvItem ) )
		lDataItem = atol( plvItem.pszText );
}
 
Share this answer
 
v3
Comments
ppontheweb.hi 29-Aug-11 11:58am    
I have tried

LVITEM* plvItem = new LVITEM();
bool ldataitem = pListCtrl->GetItem(plvItem);

In this ldataitem is true and plvItem is 0 or null. it is not returning any thing.. LVITEM is totally blank.
André Kraak 29-Aug-11 12:36pm    
I have updated the solution with the answer to your comment.
ppontheweb.hi 30-Aug-11 3:32am    
Hi Andre in the get item plvItem->pszText is null. I used pointer instead of object
André Kraak 30-Aug-11 5:34am    
Try the code right after your InsertItem statement. At this point you can be sure about the item index (iItem). Make sure that it is not -1 as the insert will have failed.

I also see I made a mistake is the code I have given. pListCtrl->GetItem( plvItem ) should be pListCtrl->GetItem( &plvItem ). I have updated the solution.
ppontheweb.hi 30-Aug-11 5:46am    
InsertItem is giving 0 but GetItem is returning false...
SQL
I used GetItemText instead of GetItemData and it solved my purpose.

Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900