|
-
February 23rd, 2007, 06:33 PM
#1
Listview selected item
I'm trying to select an item in a listview from code. However I'm having some problems. Both
Code:
ListView_SetItemState(ListViewHandle, 4, LVIS_SELECTED, LVIS_SELECTED)
and
Code:
SelectListViewItemMessage.state = LVIS_SELECTED;
SelectListViewItemMessage.stateMask = LVIS_SELECTED;
SendMessage(ListViewHandle, LVM_SETITEMSTATE, (int) 4, (LPARAM) &SelectListViewItemMessage);
don't work. However sendmessage does return TRUE.
Mayb it is due to the style of the listview? It has the following style (there is always only 1 item selected never 0 never more than 1):
Code:
WS_CHILD LVS_REPORT
WS_VISIBLE LVS_SINGLESEL
WS_VSCROLL LVS_SHOWSELALWAYS
WS_TABSTOP LVS_SHAREIMAGELISTS
LVS_OWNERDRAWFIXED
LVS_NOCOLUMHEADER
ExStyle: 0x0
-
February 23rd, 2007, 07:12 PM
#2
Re: Listview selected item
 Originally Posted by Henkie
I'm trying to select an item in a listview from code. However I'm having some problems.
First method should work.
Second should work if you also set
SelectListViewItemMessage.mask = LVIF_STATE;
Stupid question - do you have at least 5 items in that list?
<edited> Just noticed that you have an OWNERDRAW style. Then you had to draw items yourself. Do you check for the selected state?
Last edited by VladimirF; February 23rd, 2007 at 07:17 PM.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 23rd, 2007, 08:10 PM
#3
Re: Listview selected item
 Originally Posted by VladimirF
<edited> Just noticed that you have an OWNERDRAW style. Then you had to draw items yourself. Do you check for the selected state?
No I don't, should I (and why)? What I'm trying to do is click on Items in a viewlist (from an application that I did not write). I can click on the item that has the focus with
Code:
SendMessage(ListViewHandle, WM_LBUTTONDBLCLK, MK_LBUTTON, 0);
Now I need to be able to get the focus on the right item.
After restarting Borland the first method Selects an Item (colours the box blue) but does not put the focus on it and using LVIS_FOCUSED | LVIS_SELECTED does not work either.
Thanks in advance for the help.
-
February 24th, 2007, 01:00 PM
#4
Re: Listview selected item
I've temporarily solved it with a WM_KEYDOWN and VK_DOWN / VK_UP to scroll through the Items. This is a little bit dirty. If someone knows how to do it with ListView_SetItemState please let me know.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|