locked
how can I make a databound datagridview let the user re-order its rows RRS feed

  • Question

  • Suppose I have a datagridview, that I have bound to a list of classes.  I can set allowdrop to be true, but the code that I find on the web does not allow users to re-order the rows, or add new ones.

    How is it done?

    Thanks

    Sunday, December 27, 2015 1:17 PM

Answers

  • Suppose I have a datagridview, that I have bound to a list of classes.  I can set allowdrop to be true, but the code that I find on the web does not allow users to re-order the rows, or add new ones.

    How is it done?

    Thanks

    The fact that it's databound is why you can't do that.

    You can, though, reorder the data behind the DGV. The DGV will then display it like they want it.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Sunday, December 27, 2015 2:07 PM
  • Hello,

    Look at the following code sampe

    https://code.msdn.microsoft.com/windowsdesktop/Generic-sortable-binding-47cac3cc


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Monday, December 28, 2015 11:22 AM
  • The datagridview presents the data in the order as it is sorted in the classes for which it is used.

    Therefore you have to make the order in the classes in the way you present it. 

    Without a sentence "bound to a list of classes" nobody can help yo with that. It can have 10000 ways to do it.


    Success
    Cor

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Monday, December 28, 2015 12:04 PM
  • Thought I toss the following solution out there. The backend is C# which should never need altering while the actual demo is in VB.NET.

    https://onedrive.live.com/redir?resid=A3D5A9A9A28080D1!876&authkey=!AJbwmuALmj2oXr0&ithint=file%2czip


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    • Marked as answer by malikmeister Tuesday, December 29, 2015 12:53 PM
    Monday, December 28, 2015 2:48 PM

All replies

  • Suppose I have a datagridview, that I have bound to a list of classes.  I can set allowdrop to be true, but the code that I find on the web does not allow users to re-order the rows, or add new ones.

    How is it done?

    Thanks

    The fact that it's databound is why you can't do that.

    You can, though, reorder the data behind the DGV. The DGV will then display it like they want it.


    If I had eight hours to chop down a tree, I'd spend six sharpening my axe. -- Abraham Lincoln

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Sunday, December 27, 2015 2:07 PM
  • Hello,

    Look at the following code sampe

    https://code.msdn.microsoft.com/windowsdesktop/Generic-sortable-binding-47cac3cc


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Monday, December 28, 2015 11:22 AM
  • The datagridview presents the data in the order as it is sorted in the classes for which it is used.

    Therefore you have to make the order in the classes in the way you present it. 

    Without a sentence "bound to a list of classes" nobody can help yo with that. It can have 10000 ways to do it.


    Success
    Cor

    • Marked as answer by malikmeister Monday, December 28, 2015 1:15 PM
    Monday, December 28, 2015 12:04 PM
  • Thought I toss the following solution out there. The backend is C# which should never need altering while the actual demo is in VB.NET.

    https://onedrive.live.com/redir?resid=A3D5A9A9A28080D1!876&authkey=!AJbwmuALmj2oXr0&ithint=file%2czip


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter or Facebook via my MSDN profile but will not answer coding question on either.

    • Marked as answer by malikmeister Tuesday, December 29, 2015 12:53 PM
    Monday, December 28, 2015 2:48 PM