« Columns | Index | Data Binding » |
Better ListView allows settings four distinct context menu via properties:
Global context menu, used when uses clicks on client area (or on column header/item when the specific menu is not set).
Context menu for column headers.
Context menu for groups.
Context menu for items.
These are of type System.Windows.Forms.ContextMenuStrip.
Custom context menus can be displayed manually using MouseDown event and HitTest method to detect location of the cursor.
C#
// add column, group and item
this.listView.BeginUpdate();
this.listView.Columns.Add(new BetterListViewColumnHeader("some column", 256));
this.listView.Groups.Add("some group");
this.listView.Items.Add(new BetterListViewItem("some item", this.listView.Groups[0]));
this.listView.ShowGroups = true;
this.listView.EndUpdate();
// set common context menu
ContextMenuStrip contextMenuStripCommon = new ContextMenuStrip();
contextMenuStripCommon.Items.Add("Common Context Menu Item 1");
contextMenuStripCommon.Items.Add("Common Context Menu Item 2");
this.listView.ContextMenuStrip = contextMenuStripCommon;
// set column header context menu
ContextMenuStrip contextMenuStripColumnHeaders = new ContextMenuStrip();
contextMenuStripColumnHeaders.Items.Add("Column Header Context Menu Item 1");
contextMenuStripColumnHeaders.Items.Add("Column Header Context Menu Item 2");
this.listView.ContextMenuStripColumns = contextMenuStripColumnHeaders;
// set item context menu
ContextMenuStrip contextMenuStripItems = new ContextMenuStrip();
contextMenuStripItems.Items.Add("Item Context Menu Item 1");
contextMenuStripItems.Items.Add("Item Context Menu Item 2");
this.listView.ContextMenuStripItems = contextMenuStripItems;
// set group context menu
ContextMenuStrip contextMenuStripGroups = new ContextMenuStrip();
contextMenuStripGroups.Items.Add("Group Context Menu Item 1");
contextMenuStripGroups.Items.Add("Group Context Menu Item 2");
this.listView.ContextMenuStripGroups = contextMenuStripGroups;
Visual Basic
' add column, group and item
ListView.BeginUpdate()
ListView.Columns.Add (New BetterListViewColumnHeader ("some column", 256))
ListView.Groups.Add ("some group")
ListView.Items.Add (New BetterListViewItem ("some item", ListView.Groups (0)))
ListView.ShowGroups = True
ListView.EndUpdate()
' set common context menu
Dim contextMenuStripCommon As New ContextMenuStrip()
contextMenuStripCommon.Items.Add ("Common Context Menu Item 1")
contextMenuStripCommon.Items.Add ("Common Context Menu Item 2")
ListView.ContextMenuStrip = contextMenuStripCommon
' set column header context menu
Dim contextMenuStripColumnHeaders As New ContextMenuStrip()
contextMenuStripColumnHeaders.Items.Add ("Column Header Context Menu Item 1")
contextMenuStripColumnHeaders.Items.Add ("Column Header Context Menu Item 2")
ListView.ContextMenuStripColumns = contextMenuStripColumnHeaders
' set item context menu
Dim contextMenuStripItems As New ContextMenuStrip()
contextMenuStripItems.Items.Add ("Item Context Menu Item 1")
contextMenuStripItems.Items.Add ("Item Context Menu Item 2")
ListView.ContextMenuStripItems = contextMenuStripItems
' set group context menu
Dim contextMenuStripGroups As New ContextMenuStrip()
contextMenuStripGroups.Items.Add ("Group Context Menu Item 1")
contextMenuStripGroups.Items.Add ("Group Context Menu Item 2")
ListView.ContextMenuStripGroups = contextMenuStripGroups
« Columns | Index | Data Binding » |
Better Thumbnail Browser Documentation | Copyright © 2010-2012 ComponentOwl.com |