-
Kind of a beginner here, so this could very likely be something i am doing wrong. I have a listview on which i am tracking the MouseClick, KeyUp, and SelectedItemChanged events. When the listview is first loaded, i set the selected item to the first item in the list. Also, the listview has AllowsMarking and MultiSelect set to true. The first mouse click in the listview fires the MouseClick event 3 times and it fires the SelectedItemChanged event. Subsequent mouse clicks still fire the MouseClick event (3 times), but do not fire the SelectedItemChanged event. Inside the MouseClick, i am checking the listview.SelectedItem, and i do see that number changing from click to click, to the last row on which i clicked, but the SelectedItemChanged event isn't firing. The issue for me is that i am using that Change event to track the current row in the listview, so that future operations can act on one, or a collection, of items associated with the selected rows. Similar actions using the keyboard (moving between rows for example) seem to fire both the KeyUp event and SelectedItemChanged events every time. Is there something i am doing incorrectly or out of order to not get that SelectedItemChanged event to fire? Alternatively, is there some way to compute the row which was clicked in the listview? I could then capture the item associated with the row which was clicked and store it in my list of selected items. Somehow the underlying system knows which row has been clicked, because it is tracking the change to the SelectedItem and marking the correct row with a check mark and highlighting that as the selected row. Any ideas would be appreciated, and happy to share some code if needed. It is pretty straightforward for this part, just registering events and putting a breakpoint to check what is firing and when. Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
What version do you are using and a add sample code that demonstrate the issue, please. |
Beta Was this translation helpful? Give feedback.
-
Hello. I am using v 1.15.1.. Sample code below. If you run this, you can put a breakpoint in the SelectedItemChanged event and see that it never fires for the mouse clicks. If you use the keyboard to move the cursor, it does hit the breakpoint. Also notice that for each mouse click in the listview, the text field that has the selected item index, reports the index of the last item clicked, even though the GUI responds as if the row which was currently clicked is now selected (check mark, highlighted row, etc.).
|
Beta Was this translation helpful? Give feedback.
-
Ok done (I hope i did it correctly, it's my first time having a discussion on github much less converting one to an issue!) - thank you. |
Beta Was this translation helpful? Give feedback.
Thanks. I think you can convert this discussion to an issue because the
MouseClick
event should only be invoked when a button was clicked and not when the mouse is reporting mouse move and button released (That the reason of the 3 events repeated).In the same way that the selected item is changed by using the keyboard the mouse click also should fire the
SelectdItemChanged
event.You can't rely on the
MouseClick
to get the listview selected item to display on theTextField
because it's fired before theListView
process the change of the selected item.After you convert this discussion to an issue and I'll submit a PR to fix it.