Hi,
How to display a context menu in an ultra grid if and only if the user clicks on a particular row. And the row or cell should not be header or blank cell/row.
Regards,
SreeRam
Hi Mike,
As you said we can't apply a context menu to a part of a control if we choose the "ContextMenuStrip" property for ultragrid control. I tried MouseDown event to assign or remove the context menu. Although the below code works fine if and only if you remove the "ContextMenuStrip" property for ultragrid control. Because it overrides the below code and displays the context menu whereever you click the mouse within the control.
********************************************************************************
private void ugQueue_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { Point mousePoint = new Point(e.X, e.Y); UIElement element = ((UltraGrid)sender).DisplayLayout.UIElement.ElementFromPoint(mousePoint); UltraGridCell cell = element.GetContext(typeof(UltraGridCell)) as UltraGridCell; if (cell != null) { if (Convert.ToByte(cell.Row.Cells["Status"].Value) == 0) { cmnuQueue.Show(ugQueue, mousePoint); cell.Row.Selected = true; } else return; } } }
Thanks Mike.
With Regards,
SreeRam.
Hi SreeRam,
You can't apply a context menu to a part of a control. What you would have to do is apply the context menu to the entire control depending on the location of the mouse. I would use the MouseEnterElement and MouseLeaveElement events of the grid to assign and remove the context menu. You can use the GetContext method on the UIElement being entered to get the row (or null) and either set or remove the context menu on the grid control.