'宣言 Public Overloads Function ItemFromPoint( _ ByVal point As Point _ ) As UltraListViewItem
public UltraListViewItem ItemFromPoint( Point point )
Imports Infragistics.Win Imports Infragistics.Win.UltraWinListView Private Sub ultraListView1_MouseDown(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles ultraListView1.MouseDown Dim listView As UltraListView = CType(sender, UltraListView) ' Remove all context menu items Me.contextMenu1.MenuItems.Clear() ' Add context menu items for group, item, sub-item Dim groupMenuItem As IGMenuItem = New IGMenuItem("Group", New EventHandler(AddressOf OnMenuItemClick)) Dim itemMenuItem As IGMenuItem = New IGMenuItem("Item", New EventHandler(AddressOf OnMenuItemClick)) Dim subItemMenuItem As IGMenuItem = New IGMenuItem("SubItem", New EventHandler(AddressOf OnMenuItemClick)) Me.contextMenu1.MenuItems.Add(groupMenuItem) Me.contextMenu1.MenuItems.Add(itemMenuItem) Me.contextMenu1.MenuItems.Add(subItemMenuItem) ' Hit test for the group, item, or sub-item at the cursor position Dim groupAtPoint As UltraListViewGroup = listView.GroupFromPoint(e.X, e.Y) Dim itemAtPoint As UltraListViewItem = listView.ItemFromPoint(e.X, e.Y, True) Dim subItemAtPoint As UltraListViewSubItem = listView.SubItemFromPoint(e.X, e.Y) ' Assign a reference to the group, item or sub-item to the menu item's Tag groupMenuItem.Tag = groupAtPoint itemMenuItem.Tag = itemAtPoint subItemMenuItem.Tag = subItemAtPoint ' Enable the appropriate context menu items groupMenuItem.Enabled = Not groupAtPoint Is Nothing itemMenuItem.Enabled = Not itemAtPoint Is Nothing subItemMenuItem.Enabled = Not subItemAtPoint Is Nothing If listView.ContextMenu Is Nothing Then listView.ContextMenu = Me.contextMenu1 End Sub Private Sub OnMenuItemClick(ByVal sender As Object, ByVal e As EventArgs) Dim menuItem As IGMenuItem = CType(sender, IGMenuItem) If menuItem.Tag.GetType() Is GetType(UltraListViewItem) Then ' Activate and select the UltraListViewItem Dim item As UltraListViewItem = CType(menuItem.Tag, UltraListViewItem) item.Activate() item.Control.PerformAction(UltraListViewAction.SelectItem, False, False) End If End Sub
using Infragistics.Win; using Infragistics.Win.UltraWinListView; using System.Diagnostics; private void ultraListView1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { UltraListView listView = sender as UltraListView; // Remove all context menu items this.contextMenu1.MenuItems.Clear(); // Add context menu items for group, item, sub-item IGMenuItem groupMenuItem = new IGMenuItem( "Group", new EventHandler(this.OnMenuItemClick) ); IGMenuItem itemMenuItem = new IGMenuItem( "Item", new EventHandler(this.OnMenuItemClick) ); IGMenuItem subItemMenuItem = new IGMenuItem( "SubItem", new EventHandler(this.OnMenuItemClick) ); this.contextMenu1.MenuItems.Add( groupMenuItem ); this.contextMenu1.MenuItems.Add( itemMenuItem ); this.contextMenu1.MenuItems.Add( subItemMenuItem ); // Hit test for the group, item, or sub-item at the cursor position UltraListViewGroup groupAtPoint = listView.GroupFromPoint( e.X, e.Y ); UltraListViewItem itemAtPoint = listView.ItemFromPoint( e.X, e.Y, true ); UltraListViewSubItem subItemAtPoint = listView.SubItemFromPoint( e.X, e.Y ); // Assign a reference to the group, item or sub-item to the menu item's Tag groupMenuItem.Tag = groupAtPoint; itemMenuItem.Tag = itemAtPoint; subItemMenuItem.Tag = subItemAtPoint; // Enable the appropriate context menu items groupMenuItem.Enabled = groupAtPoint != null; itemMenuItem.Enabled = itemAtPoint != null; subItemMenuItem.Enabled = subItemAtPoint != null; if ( listView.ContextMenu == null ) listView.ContextMenu = this.contextMenu1; } private void OnMenuItemClick( object sender, EventArgs e ) { IGMenuItem menuItem = sender as IGMenuItem; if ( menuItem.Tag is UltraListViewItem ) { // Activate and select the UltraListViewItem UltraListViewItem item = menuItem.Tag as UltraListViewItem; item.Activate(); item.Control.PerformAction( UltraListViewAction.SelectItem, false, false ); } }