Results 1 to 6 of 6

Thread: Drag and drop rows bound datagridview

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Drag and drop rows bound datagridview

    Hi all.

    I am new to this forum and pretty new to VB.net and application development. I am trying to develop a scheduler for my workplace for which I am using a datagridview. The data displayed in the datagridview is bound to a SQL server database.

    I need to be able to drag and drop rows so that the any job with a high priority and a nearer deadline can just be dragged from anywhere in the grid and dropped to the topmost point in the grid. I don't mind using two buttons (up and down) to do it either. But I am not able to figure out a way to do it.

    Any kind of help would be appreciated. please let me know if you need any other information.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Drag and drop rows bound datagridview

    The attached project which was done by someone else, do not remember where I located it as it was sometime ago. I did tweak it a tad bit and marked where I did changes along with adding a module for language extensions.

    Any ways you can drag and drop rows but has some issues which should be fixable like if the DataGridView is sorted by the user the operation does not work and sometimes it seems unnatural doing the drag drop. If you are willing to work with it I am sure it will provide what you need although I would feel more comfortable using the logic with buttons to move a row up/down.
    Attached Files Attached Files

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Drag and drop rows bound datagridview

    Hey kevin,

    That worked well.. thanks a lot! Although for some reason when I use that in my application... there is a weird increment in the position at which the row is dragged and dropped.
    Like when I run it, the first time I do a drag drop .. it correctly does it at the position told. In the same instance, if i do a drag drop 2nd time, it drops the row 1 row above the position where I actually drop it. 3rd time... 2 rows above the position .. and that increases. do you know why?

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Drag and drop rows bound datagridview

    By the way I am using Visual Studio 2010

  5. #5
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: Drag and drop rows bound datagridview

    Quote Originally Posted by ashwat View Post
    Hey kevin,

    That worked well.. thanks a lot! Although for some reason when I use that in my application... there is a weird increment in the position at which the row is dragged and dropped.
    Like when I run it, the first time I do a drag drop .. it correctly does it at the position told. In the same instance, if i do a drag drop 2nd time, it drops the row 1 row above the position where I actually drop it. 3rd time... 2 rows above the position .. and that increases. do you know why?
    I tried to reproduce what you had happen but could not. What I can say is that drag-drop takes some getting use too in a DataGridView in this manner.

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2010
    Posts
    4

    Re: Drag and drop rows bound datagridview

    I finally was able to do it correctly.. I also ended up adding couple more functionalities like cutting and pasting of rows. Thanks a lot for your help.

    But there is one last thing that I am not able to do. Once you are done with the reordering of rows.. how do you post it back to the database? I am using multiple tables .. I used the update command and several parameters.. i am able to post back any changes I do except the change in ordering of rows.

    Any help on that would be greatly appreciated.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width