Hi,
In the MouseDown event, I save the mouse X/Y coordinates to reuse them later in the Click event to get the row/cell. My issue is when the user clicks on a row that is partially hidden, it first moves it up a little causing the coordinates to no longer be accurate.
How can I adjust the coordinates if the row is scroll into view?
Thanks.Annie
P.S. I am using version 9.2.20091.2085
What about using the MouseUp event? You can also get the mouse position in the Click event by using Cursor.Position or Control.MousePosition. Howevenr, this is in screen coordinates and you need to use grid.PointToClient method to convert it.
The code I have must be within the Click event. I tried using the Control.MousePosition method and it gives me back the same coordinates as the one I saved within the MouseDown event which is not good because the row at this point already moved to be all visible.
Annie
Hi Annie,
I'm not sure what you are trying to do here, but the Mouse isn't actually moving so the coordinates are always going to be the same. The mouse hasn't move, it's the row that has moved under the mouse. I don't know of any way around this - the grid has to scroll the row into view.
Perhaps what you should do is, instead of storing the mouse coords (which you don't really need to store, since they do not change), you could get the row in the MouseDown event and store it in an UltraGridRow variable.
Hi Mike,
I am trying to get the row from the mouse coordinates and since the row moved (and I understand it has to), the wrong row is getting retrieved.
To get the row, I am using the method you sent me a couple of days ago (MergedCells issue).
I am wondering if there is an event I could listen to when the row is scroll into view and perhaps in this case, I could get the row by calling LastElementEntered instead of trying to get it from the coordinates.
Would you know if there is such event?Thanks again.Annie
Mike Saltzman"]when you click on the grid, it changes the ActiveRow and scrolls it into view before the MouseDown fires
Going with what you said in your last reply, I added code to compare the row I get with the GetRowFromPoint method with the currently active row. If their index do not match, I use the ActiveRow.
So far so good.
Thanks for you help.Annie
Yes, I see what you mean. What happens is that when you click on the grid, it changes the ActiveRow and scrolls it into view before the MouseDown fires. Unfortunately, I don't see any way around that.
You could use the ActiveRow as the row for your context menu, but I don't see any way to detect this situation so that you would know when to use the ActiveRow and when to get the row under the mouse.
I am trying to get the row the user clicked on, within the MouseDown event as you suggested, using the mouse coordinates and it is already to late as the row has scrolled already so it seems.
Calling the GetRowFromPoint method gives me back the next row, instead of the one the user actually clicked on.
There's an AfterRowRegionScroll event which fires when the grid scrolls rows. I think it will fire in this case.
But I'm not sure I see how that helps.
If you store the row, as I suggested above, in the MouseDown event, then you will have the row the user clicked on.
If you want the row the mouse is now over instead of the row that the user clicked on, then you just have to get the row after the scroll operation has taken place using the same mouse coords you already have.
So, if you are calling the code I posted in the Click event of the grid, then I guess that might be too early and click is firing before the row has scrolled. Is that the problem? If so, then AfterRowRegionScroll probably won't fire until after Click has already fired, which means it probably won't help you.
Personally, I would try using MouseUp to do whatever you are doing in the Click event.But I think you said before that you don't want to do that.
Another possible solution is to try to force the grid's UIElements to update so that they are in the right place when you try to get the row. So you might try something like this in the Click event before you try to get the row from the point.
grid.DisplayLayout.UIElement.DirtyChildElements(true);
grid.DisplayLayout.UIElement.VerifyChildElements();
grid.Refresh();
If this works, you might try different combinations of these three lines - as you probably don't need all three. This may not work, though, I'm not sure.