Solved

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

Posted on 2009-07-04
3
337 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now