Users drag rows up and down in my DataGridView. I have the dragging logic down-pat, but I’d like there to be a dark marker indicating where the row will be placed after I let go of the mouse.
Example from Microsoft Access http://img718.imageshack.us/img718/8171/accessdrag.png
Example from Microsoft Access; I want to drag rows instead of columns
Does anyone know how I’d go about doing this? Is this built-in, or would I have to draw my own marker (if so, how do I do that)?
Thanks!
I did this for a treeview a couple years ago; can’t remember exactly how, but consider using the
MouseMoveevent of the DataGridView.While the drag is occurring, your MouseMove handler should:
mouse (the MouseEventArgs contains
the coordinates, but I think they’re screen coordinates, so you can use
DataGridView.PointToClient()to convert them to relative)position (is there a method for this? If not, you can calculate it by adding up the row + row header heights, but remember that the grid may have been scrolled)
border. One way you may be able to darken one border is by changing the
DataGridViewRow.DividerHeightproperty.row, restore it to how it previously
looked.
If you wanted to do something custom with the appearance of the row under the mouse (instead of just using the available properties), you can use the
DataGridView.RowPostPaintevent. If you implement a handler for this event which is only used when a row is being dragged over another row, you can repaint the top or bottom border of the row with a bolder brush. MSDN example here.