// JP opened flex table

Click to See Complete Forum and Search --> : Listview selected item


Henkie
February 23rd, 2007, 06:33 PM
I'm trying to select an item in a listview from code. However I'm having some problems. Both
ListView_SetItemState(ListViewHandle, 4, LVIS_SELECTED, LVIS_SELECTED)andSelectListViewItemMessage.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):
WS_CHILD LVS_REPORT
WS_VISIBLE LVS_SINGLESEL
WS_VSCROLL LVS_SHOWSELALWAYS
WS_TABSTOP LVS_SHAREIMAGELISTS
LVS_OWNERDRAWFIXED
LVS_NOCOLUMHEADER
ExStyle: 0x0

VladimirF
February 23rd, 2007, 07:12 PM
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?

Henkie
February 23rd, 2007, 08:10 PM
<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
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.

Henkie
February 24th, 2007, 01:00 PM
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.

//JP added flex table