The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: JayPee on April 14, 2009, 03:09:01 AM

Title: Help with Listview Please
Post by: JayPee on April 14, 2009, 03:09:01 AM
Hi all

I have a ListView dialog that I want to highlight a row by code rather than a mouse click, its part a a media player and I want the row that is playing to be highlighted.

Thanks
John
Title: Re: Help with Listview Please
Post by: Tedd on April 22, 2009, 04:40:03 PM
There doesn't appear to be a plain set-selection message (for list-view; for list-box it's simply lb_setcursel)..
Try LVM_SETSELECTIONMARK, if that's no good I think you'll have to resort to playing with LVM_SETITEM and set the currently-playing item's state to focussed+selected (and un-select the previous.)
Also, don't forget to LVM_SCROLL :wink
Title: Re: Help with Listview Please
Post by: JayPee on May 06, 2009, 12:25:33 AM
Hi Ted

Thanks for your help -didn't work as I expected so have given it a rest for awhile lol

Regards
John
Title: Re: Help with Listview Please
Post by: gwapo on May 06, 2009, 03:19:12 AM

; I didn't wrote this, it's only taken from EnsureVisible disassembly.

EnsureVisible proc ListViewHandle:DWORD, ItemIndex:DWORD
   invoke SendMessage, ListViewHandle, 1013h, ItemIndex, 0
EnsureVisible endp


EDIT: Sorry the above code is just to ensure that the selection is visible (scrolled).

The question is how to select a list view item, here's how:

1. Get the item's LV_ITEM structure.
2. Set the structure's state to 2 (to mark it as SELECTED)
3. Set the structure's mask to 2 (to inform the ListView that the item should be shown as visibly selected)
4. Send the structure information to listview back: invoke SendMessage, hListView, 102bh, index, addr lviStruct
5. Finally, set the selection mark: invoke SendMessage, hListView, 1043h, 0, index

-c
Title: Re: Help with Listview Please
Post by: JayPee on May 06, 2009, 07:23:19 AM
Hi
Thanks for that I will give it a try

Regards
John
Title: Re: Help with Listview Please
Post by: Jackal on May 20, 2009, 01:44:57 AM
Not sure if you figured this out but here is a piece of code from one of my apps. It allows someone to search a string in a listview and this will show it and highlight it when found.


       invoke GetDlgItemText, hWnd, 20, ADDR tmpString, 15
       cmp tmpString, NULL
       je Skip
       mov flvi.flags, LVFI_STRING or LVFI_WRAP or LVFI_PARTIAL
       lea eax, tmpString
       mov flvi.psz, eax
       INVOKE SendMessage, hList, LVM_FINDITEM, -1, addr flvi
       cmp eax, -1
       je @F
       mov tNum, eax
       mov lvi.state, 0
       invoke SendMessage, hList, LVM_SETITEMSTATE, -1, addr lvi
       mov lvi.state, LVIS_FOCUSED or LVIS_SELECTED
       mov lvi.stateMask, LVIS_FOCUSED or LVIS_SELECTED
       invoke SendMessage, hList, LVM_SETITEMSTATE, tNum, addr lvi
       invoke SendMessage, hList, LVM_ENSUREVISIBLE , tNum, TRUE