Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
Hi,

The following is code to insert an item to listcontrl.
When i add LVIF_PARAM to lvi.mask, only first subitem is shown. (list control is set as report view mode). What is problem here??

m_lstCtrl.InsertColumn(0, L"First name" , LVCFMT_LEFT, onePercent * 35);
m_lstCtrl.InsertColumn(1, L"Middle name", LVCFMT_CENTER, onePercent * 35);
m_lstCtrl.InsertColumn(2, L"Last name", LVCFMT_LEFT, onePercent * 30);

LVITEM lvi;
// Insert #0
// Check if image available
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = 0;				
lvi.iSubItem = 0;	
lvi.lParam = 100;
lvi.pszText =L"First";
m_lstCtrl.InsertItem(&lvi);
// Insert #1
lvi.iSubItem  = 1;
lvi.pszText = L"Middle";
m_lstCtrl.SetItem(&lvi);
// Insert #2
lvi.iSubItem = 2;
lvi.pszText = L"Last";
m_lstCtrl.SetItem(&lvi);



Thank.

Quy
Posted
Updated 11-May-11 7:34am
v2
Comments
Richard MacCutchan 11-May-11 3:55am    
Check the return values from your function calls for any errors. Also ensure that the item value in the SetItem() calls is the same as the return from InsertItem().

A quick google search reveals that a lot of people has problems using LVIF_PARAM with sub items. It may be a bug.

Try not to use LVIF_PARAM. You can for example add a list of your param and maintain both this list and the list control.

I know this solution is just a workaround but you will probably loose less time like that.
 
Share this answer
 
Comments
quyps 11-May-11 13:40pm    
it will do if i keep my list of param and list control in same order. thanks
Thank for the replies.
It is actually not a bug, I figured it out. This is a little subtle :)
LVITEM.mask (probably whole LVITEM struct) should be independently applied for every subitems. My mistake in above code is that I didnt reset lvi.mask.

so here is (at least in my case) a working version.

m_lstCtrl.InsertColumn(0, L"First name" , LVCFMT_LEFT, onePercent * 35);
m_lstCtrl.InsertColumn(1, L"Middle name", LVCFMT_CENTER, onePercent * 35);
m_lstCtrl.InsertColumn(2, L"Last name", LVCFMT_LEFT, onePercent * 30);
 
LVITEM lvi;
// Insert First#0
// Check if image available
lvi.mask = LVIF_TEXT | LVIF_PARAM ;
lvi.iItem = 0;				
lvi.iSubItem = 0;	
lvi.lParam = 100;
lvi.pszText =L"First";
m_lstCtrl.InsertItem(&lvi);

// Insert Middle#1
lvi.mask = LVIF_TEXT;
lvi.iSubItem  = 1;
lvi.pszText = L"Middle";
m_lstCtrl.SetItem(&lvi);

// Insert Last#2
lvi.mask = LVIF_TEXT;
lvi.iSubItem = 2;
lvi.pszText = L"Last";
m_lstCtrl.SetItem(&lvi);


Quy
 
Share this answer
 
v5
Comments
Olivier Levrey 11-May-11 5:19am    
Ok good to know.

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