Solved

How to select an item in a listview which allows only 1 selected item at a time

Posted on 2009-07-04
3
346 Views
Last Modified: 2013-12-17
Hello. I've been trying to select an item on an external listview but it seems to only work with listviews that accept multiple selected items:
HANDLE process=OpenProcess(PROCESS_VM_OPERATION|PROCESS_VM_READ|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, 0xC30); 
 
LVITEM lvi;
 
LVITEM* _lvi=(LVITEM*)VirtualAllocEx(process, NULL, sizeof(LVITEM), MEM_COMMIT, PAGE_READWRITE); 
 
 lvi.state = LVIS_FOCUSED | LVIS_SELECTED;
 lvi.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
 lvi.mask = LVIF_STATE;
 
 WriteProcessMemory(process, _lvi, &lvi, sizeof(LVITEM), NULL); 
 int abc = ::SendMessage((HWND)0x00080D6A, LVM_SETITEMSTATE, (WPARAM)0, (LPARAM)_lvi); 
 VirtualFreeEx(process, _lvi, 0, MEM_RELEASE);

Open in new window

0
Comment
Question by:devoured_elysium
  • 2
3 Comments
 
LVL 33

Expert Comment

by:pgnatyuk
ID: 24777230
Will this way with SendMessage work, if the listview will be in the current process?
There were always few steps - give focus to the listview, select the item, check that this item is visible. seems like you didn't switch the focus? or just didn't redraw the list?
0
 
LVL 33

Accepted Solution

by:
pgnatyuk earned 250 total points
ID: 24777255
In a common case it can be like that:
ListView_SetItemState(hList, -1, 0, LVIS_SELECTED);
SendMessage(hList,LVM_ENSUREVISIBLE,  (WPARAM)item, FALSE);
ListView_SetItemState(hList,item, LVIS_SELECTED ,LVIS_SELECTED);
ListView_SetItemState(hList,item, LVIS_FOCUSED ,LVIS_FOCUSED);
 
Probably you have seen that: http://www.codeproject.com/KB/combobox/listview.aspx
 
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question