473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Click and doubleclick in listview

Hello,

I want to do different actions when clicking then when doubleclicking on an
item in the listview.

With doubleclicking, clicking events is also fired.

How can I avoid doing the 2? Use Other events?
Nov 21 '05 #1
2 5250
This is standard event behaviour for this control May I suggest one
alternative would be to use Mouse Up Event for the control and then display
a context menu , ( you need to add an event for that )

some sample code

Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp

Select Case e.Button

Case MouseButtons.Right

If ListView1.SelectedItems.Count = 0 Then
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf popUp_Click)
Else
If ListView1.CheckedItems.Count > 0 Then
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Edit", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Delete", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Clear Checked",
AddressOf popUp_Click)
ContextMenu1.MenuItems.Add("Move to List", AddressOf
popUp_Click)
Else
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Edit", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Delete", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Move to List", AddressOf
popUp_Click)
End If
End If

ContextMenu1.Show(DirectCast(sender, Control), New
Point(e.X, e.Y))
Case MouseButtons.Left

'*** ETC ETC ****

Private Sub popUp_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim cc, sp As Point
Dim cmi As MenuItem
Dim newItem As ListViewItem
Dim delItem As ListViewItem

cmi = DirectCast(sender, MenuItem)
Select Case cmi.Text
Case "Edit"
If ListView1.SelectedItems.Count = 1 Then
ListView1.SelectedItems(0).BeginEdit()
End If

**** ETC ETC *****

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mark" <Ma**@Foreign.com> wrote in message
news:eU**************@TK2MSFTNGP14.phx.gbl...
Hello,

I want to do different actions when clicking then when doubleclicking on an item in the listview.

With doubleclicking, clicking events is also fired.

How can I avoid doing the 2? Use Other events?

Nov 21 '05 #2
This is standard event behaviour for this control May I suggest one
alternative would be to use Mouse Up Event for the control and then display
a context menu , ( you need to add an event for that )

some sample code

Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp

Select Case e.Button

Case MouseButtons.Right

If ListView1.SelectedItems.Count = 0 Then
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf popUp_Click)
Else
If ListView1.CheckedItems.Count > 0 Then
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Edit", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Delete", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Clear Checked",
AddressOf popUp_Click)
ContextMenu1.MenuItems.Add("Move to List", AddressOf
popUp_Click)
Else
ContextMenu1.MenuItems.Clear()
ContextMenu1.MenuItems.Add("Add", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Edit", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Delete", AddressOf
popUp_Click)
ContextMenu1.MenuItems.Add("Move to List", AddressOf
popUp_Click)
End If
End If

ContextMenu1.Show(DirectCast(sender, Control), New
Point(e.X, e.Y))
Case MouseButtons.Left

'*** ETC ETC ****

Private Sub popUp_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
Dim cc, sp As Point
Dim cmi As MenuItem
Dim newItem As ListViewItem
Dim delItem As ListViewItem

cmi = DirectCast(sender, MenuItem)
Select Case cmi.Text
Case "Edit"
If ListView1.SelectedItems.Count = 1 Then
ListView1.SelectedItems(0).BeginEdit()
End If

**** ETC ETC *****

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Mark" <Ma**@Foreign.com> wrote in message
news:eU**************@TK2MSFTNGP14.phx.gbl...
Hello,

I want to do different actions when clicking then when doubleclicking on an item in the listview.

With doubleclicking, clicking events is also fired.

How can I avoid doing the 2? Use Other events?

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Thom Little | last post by:
I would like three states on an icon ... Left Click Right Click Double Click Left Click is fired at least once on a Double Click Is there a good example that shows how to determine if the...
1
by: cody | last post by:
How can I prevent column autosizing on doubleclick on columnheader in a ListView? -- cody Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
3
by: active | last post by:
DoubleClick seems to work OK with a ListBox. However, with a ListView I never get the event fired. I looked at both the LIstBox and ListView events and neither lists the DoubleClick??? But...
2
by: active | last post by:
I'm about ready to give up unless someone has an idea. Trying to do in a ListView DragDrop and DoubleClick. I can make it work if they use different mouse buttons. But if I use the left...
1
by: Tom | last post by:
Hi I have a listview with an event for mousemove and double click. Since implementing a handler for the mousemove event the double click event never gets fired, can anyone tell me how i should...
0
by: Mark | last post by:
Hello, I want to do different actions when clicking then when doubleclicking on an item in the listview. With doubleclicking, clicking events is also fired. How can I avoid doing the 2? Use...
0
by: Lloyd Sheen | last post by:
I am trying to do two things from a listview. First is on a double click to perform an action on the object which was double clicked. FullRowSelect is set to true for the Listview. Code for the...
3
by: Siv | last post by:
Hi, I have a ListView control in a Windows application, currently single clicking a customer name in this list, selects the customer and displays their details in text boxes to the right of the...
2
by: Boni | last post by:
Dear all, I am interested in mouse down and double click events of a control. When doubleclick happens the processing for mouse down should't be done I did follwing: sub MyMouseDown(.) handles...
1
by: =?Utf-8?B?WVhR?= | last post by:
When double-click the listview item with checkbox (View = Details), the checkbox will be checked or unchecked, how to disable this behavior? thank you.
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.