PlanetSquires Forums

Support Forums => Other Software and Code => Topic started by: Jean-pierre Leroy on March 06, 2011, 07:51:40 PM

Title: ListView functions different values if we use the keyboard or the mouse ???
Post by: Jean-pierre Leroy on March 06, 2011, 07:51:40 PM
Dear all,

You will find enclosed a very simple project to illustrate a weird problem I have with the function FF_ListView_GetSelectedItem()

When I use the keyboard, both functions FF_ListView_GetSelectedItem() and ListView_GetNextItem() return the same selected row.

When I use the mouse, the function FF_ListView_GetSelectedItem() always returns the previous selected row; only the ListView_GetNextItem() return the current selected row.

What's wrong with the FF_ListView_GetSelectedItem() when used with the mouse ?

Can you try this project and tell me if you have the same behavior on your PC.

Thanks a lot,
Jean-Pierre
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Paul Squires on March 06, 2011, 10:31:51 PM
The best approach for determining the correctly selected line in a Listview during the LVN_ITEMCHANGED notification is to use the code I posted here:

http://www.planetsquires.com/protect/forum/index.php?topic=2361.0

Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Rolf Brandt on March 07, 2011, 04:09:25 AM
I usually catch it in the %NM_CLICK event in the form's custom handler.
(Does basically the same, but I think Paul's code is more elegant!)
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Jean-pierre Leroy on March 07, 2011, 05:41:13 AM
Rolf, thank you for your input; for the application I'm working on, I would like to show data in another control based on the selected row; the user can use the arrow keys or click directly with the mouse on a specific line; the %NM_CLICK event works only when the user click directly with the mouse on a selected line; when the user uses the arrow key it doesn't work.

Paul, I've updated the LVN_ITEMCHANGED message handler with the code that you posted, but it didn't change anything; when I use the mouse, the function FF_ListView_GetSelectedItem() always returns the previous selected row; only the ListView_GetNextItem() return the current selected row; when I use the keyboard, it works! strange ?

Any other ideas ?

Thanks
Jean-Pierre

Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Rolf Brandt on March 07, 2011, 05:51:37 AM
Same here Jean-Pierre.
In one of my applications I use two connected listviews - one for the datalist and one to display the current record. To always get the right record I use the %NM_CLICK event for the mouse and the LVN_CHANGE event for the keyboard.

I always use both.
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Jean-pierre Leroy on March 07, 2011, 09:21:29 AM
Rolf,

Thank you for testing the project.

I don't know the LVN_CHANGE; do you mean LVN_ITEMCHANGED or LVN_ITEMCHANGING ?

Jean-Pierre
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Rolf Brandt on March 07, 2011, 09:39:18 AM
Excactly. That is of course what I meant - LVN_ITEMCHANGED.
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Jean-pierre Leroy on March 07, 2011, 10:52:23 AM
Dear all,

Finally I found in Jose Roca Include files (ListViewCtrl.inc) a wrapper for the message %LVM_GETNEXTITEM that returns the currently selected item.

This function ListView_GetSelection() works in all cases : with the keyboard or with the mouse.

You'll find below the latest version of the demo project.

PS for Paul: I think the confusion comes from the fact the FireFly wrapper FF_ListView_GetSelectedItem() is in fact a wrapper for the %LVM_GETSELECTIONMARK message and should have been called (just my 2 cents) FF_ListView_GetSelectionMark(); and then it could be nice to add a new FireFly function called FF_ListView_GetSelection()

Thanks,
Jean-Pierre
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Roger Garstang on March 07, 2011, 02:05:24 PM
I think I ran into that early on when the LV FF Functions were released.  I usually have multiple selections and since it only gives the starting point of the list I kept using my own %LVM_GETNEXTITEM loop that processes how I want.  In a lot of my applications I make my loop a hybrid to allow canceling too by unselecting the items as I process them.  Since it only processes selected items they can unselect them while others are still processing and abort them.

What would be cool is an FF Function extending %LVM_GETNEXTITEM with a couple extra parameters to specify what type of selection (Dotted Focus, Highlight Bar, Checkbox[May need other API calls to check this]), and the next search start position(You can pass -1 or previously found item).  Maybe a flag to reverse the selection found too so it unselects as it goes.
Title: Re: ListView functions different values if we use the keyboard or the mouse ???
Post by: Rolf Brandt on March 07, 2011, 02:07:27 PM
Excellent research, Jean-Pierre!