Jump to content
Sign in to follow this  

Detect Viewlist selection changes to update another control

Recommended Posts


I am using a Viewlist to show a list of users. Beneath the Viewlist I want to show a Label or (readonly) EditControl with extra info about the active/selected user.

I want to change the user info every time the selection changes.

After Googling for hours I found a way to do this with Accelerator Tables, but can it be done with e.g. GetMsg() or WM_notify?

TIA for any help,

Martijn (Sontec)

Keywords: keypressed, cursor key, trigger, event

Share this post

Link to post
Share on other sites

Check the example for _GUICtrlListView_Create() in helpfile, it shows how to work with WM_NOTIFY and listviews :)

Hi AdmiralAlkex, I looked at _GUICtrlListView_Create(), after some googling and reading some post of yours on _GUICtrlListView_Create, I ended with the example of _GUICtrlListView_HitTest,

which is almost the same example but easier to understand because it doesn't have al those remarks.

I managed at "Case $LVN_KEYDOWN" (see Func WM_NOTIFY) to determine when the up-key (flag=2490368) and down-key (flag=2621440) were pressed and calling an function to update my item-info's Labelcontrol.

However, I use _GUICtrlListView_GetSelectedIndices to get the current selected item and noticed that _GUICtrlListView_GetSelectedIndices only gets updated after it a return from the WM_Notify-function.

That triggered me to check for a selection after the Endswitch of GuiGetMsg() and it worked!

This is partly how I did it:

; Set focus and selection on first row of Listview
_GUICtrlListView_SetItemFocused($hListView, 0)
_GUICtrlListView_SetItemSelected($hListView, 0)

; initialize $Test1 with the Listview index of the current selected item

$Test1= _GUICtrlListView_GetSelectedIndices($hListView)

; Loop until user exits
While 1
  Switch GUIGetMsg()

  $Test2 =  _GUICtrlListView_GetSelectedIndices($hListView)  ; Get the current selected item
  If $Test1<>$Test2 Then
   _UpdateMyInfo($Test2)                                                          ; if selected item has changed then update the info
   $Test1 = _GUICtrlListView_GetSelectedIndices($hListView)  ; update $Test1 to check for the next selection change

At my function _UpdateMyInfo ($MyListViewIndex), I use _GUICtrlListView_GetItemParam($hListView, $MyListViewIndex) to determine my arrayindex to retrieve the extra user info.

The bonus with this solution: It works for all item selectionchanges, whether they were made by a keypress or mouse click!

Thank you AdmiralAlkex for pointing me to the "right" direction and a solution.

Edited by Sontec

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this