selecting listview

Started by paulDiagnos, January 20, 2005, 09:11:35 AM

Previous topic - Next topic

paulDiagnos

FF_ListView_SetSelectedItem (hwnd,  4, )

why wont the above code set the listview item witha  nice blue box?

another thing that drives me crazy

TechSupport

Hi Paul,

Listviews are not the easiest control to work with. Try the following code based on code from Kev Peel.


Sub ListView_Select(ByVal hWnd As Dword, ByVal nIndex As Long)
 Dim lvi As LV_ITEM
 lvi.iItem = nIndex
 lvi.mask = %LVIF_STATE
 lvi.State = %LVIS_SELECTED Or %LVIS_FOCUSED
 lvi.stateMask = %LVIS_SELECTED Or %LVIS_FOCUSED
 SendMessage hWnd, %LVM_SETITEM, 0, VarPtr(lvi)
 SendMessage hWnd, %LVM_ENSUREVISIBLE, nIndex, %False  
 SetFocus hWnd
End Sub


Without the "SetFocus" line it appears that you will not get the bright blue highlight, but rather the light gray.

Hope this helps.

Rainer Wiedemann

Hi,
the code obove works fine, but now I've got an other problem: I want to remove the selection, so that the next query of selected item is -1 (nothing selected). I don't succed in doing this. (In listboxes the index is 1 based and if one sets selected to 0 the selection will be removed. When I set here -1  I get the first item selected.)
What can I do?
Thanks for your help.
Regards Rainer

TechSupport

Try the following to deselect all selected items in a ListView:

ListView_SetItemState HWND_FORM1_LISTVIEW1, -1, 0, %LVIS_SELECTED   '// deselect all items


Source: http://www.codeproject.com/listctrl/listview.asp

Rainer Wiedemann

Thanks a lot - it works fine!
Rainer  :D