Hi all,Im new to Infragistics, currently I'm trying to add a context menu for my ultraGrid, so when user right-click any data in the grid, and select "show detail" menu, it will send 2 key data into variables then display another pop-up screen with this 2 variables.
Can I request a step by step sample what should I do to get the data when right-click and how should i use mouseDown or mouseMove?
Any guidance/suggestions/examples are greatly appreciated.
Thank you very much,Peace
Hello,
As far as I understand in your scenario you need to get cell value when the user right click on it. To do this you could handle OnMouseDown event of the UltraGrid, and if user is clicked on the cell to get this cell value. You could do this if you write the following code in the event like:
if (e.Button == System.Windows.Forms.MouseButtons.Right)
{
UIElement el = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(Cursor.Position);
UltraGridCell cell = GetCell(el);// Get cell from point coordinates
if (cell != null)//if there is a cell
//write your code in order to display context menu
object value = cell.Value;// get cell vale
cell.Value = value;// set cell value
}
And here is the implementation of GetCell metod:
private UltraGridCell GetCell(UIElement element)
if (element == null || element.Parent == null)
return null;
if (element.Parent is CellUIElement)
return ((CellUIElement)element.Parent).Cell;
else
return GetCell(element.Parent);
And here is some link about using of context menu:
http://msdn.microsoft.com/en-us/library/aa984254%28v=vs.71%29.aspx
http://msdn.microsoft.com/en-us/library/system.windows.forms.contextmenustrip.aspx
let me know if you have any further questions.
Hi Hristo,
Thanks for your guide.
If I only want to get the active row number when I do the right-click action, is that need to use movedown function too? How should I code to grap the row number and index number by a right-click?
Thank you very much.
Warm regards,
Peace
Use the code below, and make use of ActiveRow to get the information you need about the row you're right clicking on.
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; //Now you can access what ever cell values you need through ActiveRow. //And you can put your context menu showing code here. } } }
Thanks alot. I able to the get active row by the right click button.
Now I have to think how should I pass the active row data from MouseDown to subContextMenu_click function. hmmm
private void toolStripMenuItem_Click(object sender, EventArgs e) {
ToolStripMenuItem t = (ToolStripMenuItem) sender;
ContextMenuStrip s = (ContextMenuStrip)t.Owner;
DataGridView aCell = (DataGridView)s.SourceControl;
MessageBox.show(aCell.CurrentRow.Index.ToString());