c# - DataGridView Selected Row Move UP and DOWN -


how can allow selected rows in datagridview (dgv) moved or down. have done before listview. unfortunetly, me, replacing dgv not option (curses). way, dgv datasource generic collection.

the dgv has 2 buttons on side, yes, & down. can point me in right direction. have code used listview if it'll (it did not me).

if programatically change ordering of items in collection, dgv should reflect automatically.

sloppy, half-working example:

list<myobj> foo = dgv.datasource; int idx = dgv.selectedrows[0].index; int value = foo[idx]; foo.remove(value); foo.insertat(idx+1, value) 

some of logic may wrong, , may not efficient approach either. also, doesn't take account multiple row selections.

hmm, 1 last thing, if you're using standard list or collection isn't going go smoothly. list , collection on't emit events dgv finds useful databinding. 'burp' databinding every time change collection, better solution use system.componentmodel.bindinglist. when change ordering of bindinglist dgv should reflect change automatically.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -