View previous topic :: View next topic |
Author |
Message |
WaqasK
Joined: 21 Oct 2006 Posts: 32
|
Posted: Thu Dec 27, 2007 1:19 am Post subject: Ctrl + MouseUp event |
|
|
Hi,
I currently have a mouseup event in my app which works fine when I click on the associated virtualtree. However, if I press and hold the control key and then click on the tree the mouseup event will not fire. Do I have to craete a seperate event handler for this? Or is there a way to make the maouseup event handle this?
Thanks,
Waqas |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Dec 27, 2007 10:06 am Post subject: |
|
|
Have you added a handler to the VirtualTree.MouseUp event? I've just tested this and the event still fires when the control key is held down. Maybe you could simulate the issue you are having in a simple sample project and email us the zipped project to check out the problem. _________________ Infralution Support |
|
Back to top |
|
|
WaqasK
Joined: 21 Oct 2006 Posts: 32
|
Posted: Fri Dec 28, 2007 6:02 pm Post subject: |
|
|
Ok, I've realised what the problem is. I have a mouseUp event for the virtual tree that would do 2 things depending on whether any items have been selected when the event fires:
Code: | Private Sub VirtualTree1_Click(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles VirtualTree1.MouseUp
If VirtualTree1.SelectedItem IsNot Nothing Then
'Do this
Else
'Do somthing else
End If
End Sub |
What I found initially was that the event would fire when I clicked the mousebutton but not when I used ctrl + click. So I added the code below to see exactly what the value of the Tree.SelectedItems.Count property was when the event was fired:
Code: | Label2.Text = VirtualTree1.SelectedItems.Count.ToString |
What I found was if i clicked on a single item the selecteditems count value would change to 1 as expected. Then, when I used ctrl + click on the same item to deselect it the event did fire again (you were right!) but the selecteditems.count value did not change to 0 as it should but remained 1.
So the problem is that the SelectedItems.Count property did not update with the ctrl + click scenario. I copied the code from the mouseUp handler into a SelectionChanged event and ran it again and found that the value of the SelectedItems.Count property did update on ctrl + click.
I am not sure whether this is a bug or not. At the moment we are using a workaround by incorporating both event handlers into our app with mouseup handling the SelectedItems.Count is greater that 0 scenario and selectionchanged handling count is less than or equal to 1. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Fri Dec 28, 2007 9:10 pm Post subject: |
|
|
This isn't a bug - but due to the order in when the mouse button events are processed when handling item selection in Virtual Tree. As you have discovered, if you want to do something when the the selection has changed you should handle the SelectionChanged event. _________________ Infralution Support |
|
Back to top |
|
|
WaqasK
Joined: 21 Oct 2006 Posts: 32
|
Posted: Sat Dec 29, 2007 5:19 pm Post subject: |
|
|
Ok, no problem. We'll continue forward with our current solution. Thanks for the usual great support.
Waqas |
|
Back to top |
|
|
|