473,405 Members | 2,282 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 5247
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.