How To Move Rows In A DataGrid?

  • Thread starter Thread starter Kris
  • Start date Start date
K

Kris

I have a VB.NET app that contains a datagrid. The user needs to be
able to click on a row header and drag that row up or down in the
list. Does anyone know how to add this functionality?
 
Hello Kris,

You will have to react on MouseDown/MouseUp/MouseMove events. First, handle
the MouseDown event and MouseMove event to catch when the user starts
dragging a row header (use HitTest method to determine where exactly the
user has clicked). Then, capture a mouse and start continuously tracking
mouse pointer position (with the MouseMove event, perhaps). Whenever the
mouse pointer is over a grid row (you can determine this with the HitTest
method as well), draw some indicator below this row to notify the user the
row being dragged will be moved here (a horizontal line can be OK, I think).

Then, upon the user dropping the row being dragged (MouseUp event), you will
need to move the underlying data row to its new place.

That's basically it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top