Click here to Skip to main content
15,887,881 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I'm trying to remove the selected item from the list view, the "ListView_GetItem()" returns empty text. Here just added my code for getting selected text item from the list view.


LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
			wchar_t str[1024];
			lvitem.cchTextMax= 552;
			lvitem.mask= LVIF_TEXT;
			lvitem.iItem= selectedItem;
			lvitem.pszText= str;
			ListView_GetItem(listView, &lvitem);
			// Here Printing "lvi.pszText" text
}


Note: I'm using windows 10 OS. It's working correctly for me. But it's not working in few systems that also have same Windows 10 OS.



Give me any suggestions to resolve this problem...

What I have tried:

When I'm trying to remove the selected item from the list view, the "ListView_GetItem()" returns empty text. Here just added my code for getting selected text item from the list view.


LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
			wchar_t str[1024];
			lvitem.cchTextMax= 552;
			lvitem.mask= LVIF_TEXT;
			lvitem.iItem= selectedItem;
			lvitem.pszText= str;
			ListView_GetItem(listView, &lvitem);
			// Here Printing "lvi.pszText" text
}


Note: I'm using windows 10 OS. It's working correctly for me. But it's not working in few systems that also have same Windows 10 OS.
Posted
Updated 20-Apr-19 11:52am
Comments
KarstenK 26-Mar-19 9:41am    
typo: max char should be <512 :-O
Rick York 26-Mar-19 13:11pm    
Have you tried to print str? That is where the text should be placed.
Piraisudan 26-Mar-19 13:47pm    
Yes I tried. But it's working in some system and not working in some other system. What I'm missing? Or what's that reason?

You didn't set lvitem.iSubItem = 0;
By the way, how do you check the return string?
 
Share this answer
 
Comments
Piraisudan 27-Mar-19 6:55am    
Thanks, @CPillini... It worked like a charm...
CPallini 27-Mar-19 7:55am    
You are welcome.
Here is your fixed code:

LVITEM lvitem;
int item = ListView_GetNextItem(listView, -1, LVNI_SELECTED);

if (selectedItem != -1)
{
	wchar_t str[1024];
	lvitem.cchTextMax = 552;
	lvitem.mask = LVIF_TEXT;
	lvitem.iItem = selectedItem;
	lvitem.pszText = str;
	lvitem.iSubItem = 0;
	ListView_GetItem(listView, &lvitem);
	// Here Printing "lvi.pszText" text
}
 
Share this answer
 
I am surprised this works ANYWHERE. Try something like this :
C++
int selectedItem = ListView_GetNextItem(listView, -1, LVNI_SELECTED);
if( selectedItem != -1 )
{
    LVITEM lvitem = { 0 };
    const int strsize = 511;
    wchar_t str[strsize+1] = { 0 };
    lvitem.cchTextMax= strsize;
    lvitem.mask= LVIF_TEXT;
    lvitem.iItem= selectedItem;
    lvitem.pszText= str;
    ListView_GetItem( listView, &lvitem );
    // Here Printing "lvi.pszText" text
}
 
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