|
-
Jan 13th, 2004, 11:15 AM
#1
Thread Starter
Lively Member
Right click menu on a listview [RESOLVED]
I am having trouble trying to figure out how to convert this code from VB6 to .Net.
It checks to see if the user actually right clicks on a selectable item or in blank space. If it is a selectable item, the popup menu appears. If it is in blank space, nothing happens.
I don't know if this is the best way to do this, but it worked so I used it.
Thanks!
VB Code:
Private Sub lvCollections_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim i As Integer
'Clear all highlighted items
Set lvCollections.DropHighlight = Nothing
'Check if right mouse button was pressed
If Button = vbRightButton Then
'Clear all selected items
For i = 1 To lvCollections.ListItems.Count
lvCollections.ListItems(i).Selected = False
Next
'Using the mouse cords, do a HitTest to see if there is a selectable item.
'If there is, make it the selected item and highlight it.
Set lvCollections.SelectedItem = lvCollections.HitTest(X, Y)
Set lvCollections.DropHighlight = lvCollections.HitTest(X, Y)
On Error GoTo err
'If there was not an item selected, an error will be returned on the next line
'and jump to the err: code. If an item was selected, the popup menu will be displayed.
If Len(lvCollections.SelectedItem) <> 0 Then
PopupMenu mnuTree
End If
End If
Exit Sub
err:
err.Clear
On Error GoTo 0
End Sub
Last edited by spdracr; Jan 13th, 2004 at 01:10 PM.
-
Jan 13th, 2004, 12:11 PM
#2
like this maybe ...
VB Code:
Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp
Dim lvi As ListViewItem = ListView1.GetItemAt(e.X, e.Y)
If Not lvi Is Nothing Then
'/// code to handle your menu here.
Else
MessageBox.Show("no item selected")
End If
End Sub
~
if a post is resolved, please mark it as [Resolved]
protected string get_Signature(){return Censored;}
[vbcode][php] please use code tags when posting any code [/php][/vbcode]
-
Jan 13th, 2004, 12:17 PM
#3
Thread Starter
Lively Member
Last edited by spdracr; Jan 13th, 2004 at 01:07 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|