PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: paulDiagnos on January 20, 2005, 09:11:35 AM

Title: selecting listview
Post by: paulDiagnos on January 20, 2005, 09:11:35 AM
FF_ListView_SetSelectedItem (hwnd,  4, )

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

another thing that drives me crazy
Title: selecting listview
Post by: TechSupport on January 20, 2005, 10:53:46 AM
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.
Title: Remove Selection from a ListView
Post by: Rainer Wiedemann on February 15, 2007, 02:55:32 PM
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
Title: selecting listview
Post by: TechSupport on February 16, 2007, 04:08:36 PM
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
Title: selecting listview
Post by: Rainer Wiedemann on February 17, 2007, 12:52:46 PM
Thanks a lot - it works fine!
Rainer  :D