Hi,
I am attempting to write code where the user can select/drag some rows and drop it to another area in the same grid. What I would like to happen is to highlight somehow the destination row (preferably by change the border) so that the user can visually see where they are dropping the data. So as the selection is dragged over a number rows then each row is highlighted on enter and returns back to it normal state on leave.
How would I achieve this? Anybody have any examples?
Thanks in advance.
Nish
Hi Nish,
Changing the border color of a row is not an easy thing to do, because a row does not draw all 4 of it's own borders. You can use the row.Appearance.BorderColor, but this will probably only change the color of 1 or 2 sides, so it probably won't work well.
If you want to use the BackColor of the row, then it would be a lot easier. You just have to use the DragOver event and determine what row the mouse is over and apply an appearance to that row. The only part of this that is at all tricky is determining what row the mouse is over.
Here's a KB article that will explain how you do it:
HOWTO:UltraWinGrid Mouse Position and Row Identification
Note, however, that the article uses the MouseMove event which gives you the X and Y position of the mouse in control coords. The drag events will give you the X and Y in screen coords. So you will need to use grid.PointToClient to convert the X and Y values into grid coords.
Hi Mike,
I am using Infragistics version 13.1. I created a very simple form that lets users to move rows in UltraGrid around by dragging and dropping them.
The problem is - as the user above has mentioned - that it is hard to figure out where the record that is being dragged will be dropped.
Is there a built in capability for this now (it has been over 5 years since the original post, and things may have changed), or may be you can point me to a sample code that implements it.
Thank you in advance for your help.
Helen.
Thank you Mike!!!
It all works perfectly now.
Hi Helen,
How you reset the color depends on how you are setting the color. If you are applying an Appearance to the row or cells, then you need to reset those same appearance properties on the same row or cell.
It's typically best practice to use the InitializeRow event for this kind of thing. The event fires any time any value in any cell of the row changes, so that alleviates the need to loop.
But if you are coloring a cell on MouseMove, then the best thing to do is probably to store the row(s) that you colored in a variable, and then you can get back to that row any time you want to reset the appearance.
your code works beautifully, thank you! I have just one more question.
As you suggested earlier in this post, I am changing the background color for the rowUnderMouse. But I can not figure out how to reset previously highlighted rows back to the original color. I ended up looping through all the rows in a grid, but this affected the performance.
Is there a better way?
Thank you,
No, there haven't been any changes in this area. But it's really not hard at all to determine where the row will be dropped. The article I posted a link to above gives you the code. The only thing you have to do is convert from screen coordinates to control coordinates. And that's just a single method call.
void ultraGrid1_DragOver(object sender, DragEventArgs e) { var grid = (UltraGrid)sender; Point pointInScreenCoords = new Point(e.X, e.Y); Point pointInControlCoords = grid.PointToClient(pointInScreenCoords); UIElement element = grid.DisplayLayout.UIElement.ElementFromPoint(pointInControlCoords); if (null != element) { UltraGridRow rowUnderTheMouse = element.GetContext(typeof(UltraGridRow)) as UltraGridRow; if (null != rowUnderTheMouse) Debug.WriteLine("The mouse is over row: " + rowUnderTheMouse.Index.ToString()); } }