how to move row next and previous in datatable c#

NazHim 206 Reputation points
2021-05-15T15:52:18.513+00:00

hi all
how to. dynamically move row next and previous in datatable in c#
without using database
can possible it?
can provide some code snippet?

with best regards
NazHim

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,591 Reputation points Volunteer Moderator
    2021-05-16T01:32:15.48+00:00

    Sure it's possible. If you load data from a file (xml, json, csv) and display this data in a DataGridView, ListView or ListBox where you assign the DataTable to a BindingSource then the BindingSource becomes the data source for the control then use the language extensions I created in tangent with two buttons, one up one down. This will allow rows to be moved up/down.

    From here before saving you might consider having a column to identify the row position and loop through the rows and assign values to the row position column.

    Although the following article uses a database as mentioned earlier this can be done without a database but the article does use a database.

    Microsoft TechNet Wiki: C# DataGridView - ListBox - CheckListBox - ListView move items up/down

    96888-figure1.png

    In closing, if I had a non-database version I'd post it but my guess is less than one percent of developers use files as a source for storing information rather than use a database. And some of them are importing/exporting from databases.

    1 person found this answer helpful.

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.