Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2009-07-04
3
Medium Priority
?
368 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 1000 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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 …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

660 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