Hi,
Whenever the mouse cursor is on the ultragrid, i want to get the row which is under the mouse cursor.
i tired with MouseEnterElement and MouseHover event of the grid and wrote following line of code to get the row, but ended up with exception(cannot cast UltraGrid to UltraGridRow).
UltraGridRow uRow; uRow = (UltraGridRow)sender;
what is the right way to get a row under mouse cursor.?
Thanks,Chitra
Hello Chitra,
I am just checking about the progress of this issue. Let me know if you need our further assistance on it.
Thank you for using Infragistics Components.
Hi Chitra,
You can get the X and Y coordinates from he event arguments. But you don't absolutely need them:
private void ultraGrid1_MouseMove(object sender, MouseEventArgs e) { UltraGrid grid = (UltraGrid)sender; UIElement element = grid.DisplayLayout.UIElement.LastElementEntered; if (null == element) return; if (!(element is RowUIElement)) element = element.GetAncestor(typeof(RowUIElement)); if (null == element) return; UltraGridRow row = element.GetContext(typeof(UltraGridRow)) as UltraGridRow; if (null == row) return; Debug.WriteLine(row.Index, "The mouse is over row:"); }
Hi mike ,
Can you please provide me (UltraWinGrid Mouse Position and Row Identification) code in C# , i am not able to find X and Y cordinates ....
THanks
chitra
HOWTO:UltraWinGrid Mouse Position and Row Identification
When you use MouseEnterElement event and the mouse is over the UltraGrid sender of the event is UltraGrid. This is why when you try to cast the sender to UltraGridRow you get this exception. You can use UIElementEventArgs of this event to get the row you need. First you need to get the element the mouse has entered like this:
UIElement currentElement = e.Element;
Then you can try cast the current element to UltraGridRow like this:
UltraGridRow currentRow = (UltraGridRow)currentElement.GetContext(typeof(UltraGridRow));
In this moment if the mouse is over the UltraGrid you have reference to the row the mouse has entered. More about navigation and selection in UltraGrid you can find by following the next link: http://help.infragistics.com/Doc/WinForms/current/CLR4.0/?page=WinGrid_Navigation_and_Selection.html
Please find attached a sample solution implementing UltraGrid current row tracking.
Please let me know if this is what you are looking for or if I am missing something.