I've an UltraGrid like this:
Column1 Column2 Column3 ---------- 0 ABC ABB 0 XYZ XXZ 1 CCB AAA 2 QWE ASD 1 ASX ZAW
I'm trying to add context menu to a specific row/column in UltraWinGrid, i.e, if column1 = 0 then contextmenu1, if coumn1 =1 then contextmenu2, if column1 = 2 then contextmenu3 ( all the 3 contextmenus are have different menu items.) Can you please help???
It is better to use the location of the mouse click instead of the active cell. Use the following to get the column name based on where the mouse was clicked (this is VB.Net):
Dim cell As UltraGridCell = CType(element.GetContext(GetType(UltraGridCell)), UltraGridCell)
Then use this to get the key name for the cell:
cell.Column.Key
Hi Torrey
Thanks for the idea.
I'm trying to use the follwoing conditions :
If Column1 = 0 then display contextmenu1
If Column1 = 1 then display contextmenu2
If Column1 = 2 then display contextmenu3
use the conditions in any easier way if we can do it at all : column1 or rows to determine which contextmenu to display
Use the MouseDown event of the UltraGrid. Then you can do something such as:
ContextMenu defaultContextMenu; public frmMain() { InitializeComponent(); defaultContextMenu = ultraGrid1.ContextMenu; } private void ultraGrid1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { UIElement element = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(e.Location); if (element == null || element.Parent == null) return; Infragistics.Shared.ISelectableItem theitem = element.SelectableItem; if (theitem is UltraGridCell) { ultraGrid1.ActiveRow = ((UltraGridCell)theitem).Row; ultraGrid1.ActiveCell = theitem as UltraGridCell; switch (ultraGrid1.ActiveCell.Column.Key) { case "Column1": ultraGrid1.ContextMenu = contextMenu1; break; case "Column2": ultraGrid1.ContextMenu = contextMenu2; break; case "Column3": ultraGrid1.ContextMenu = contextMenu3; break; default: ultraGrid1.ContextMenu = defaultContextMenu; break; } } else { ultraGrid1.ContextMenu = defaultContextMenu; } } }