Solved

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

Posted on 2009-07-04
3
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

739 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