Question Datagrid ordering

dsk96m

Well-known member
Joined
Jan 11, 2013
Messages
173
Programming Experience
1-3
I am trying to move rows up and down in a datagrid. I got that working, it just swaps values in the order column. My problem is when I delete a row. How do I deal with order column when i delete a row.
 
First of all, do you really mean DataGrid or do you actually mean DataGridView? They are two different controls and the DataGridView basically superseded the DataGrid from .NET 2.0.

As for the question, why do you have to do anything? Let's say that you have 10 rows numbered 1 to 10. If you then remove row number 5, you are left with rows 1, 2, 3, 4, 6, 7, 8, 9 and 10. If you continue to swap those row numbers then won't it keep the rows ordered as you want just as before? It's only the relative values that matter so having a gap somewhere will make no difference. You could put gaps in yourself in the first place and it would still work, e.g. if you were to use numbers 1, 10, 100, 1000, 10000, 100000, etc, then you could still reorder the rows by simply swapping those numbers because the relative order of those numbers would still be the same as if they were sequential.
 
yes, sorry, data grid view. There is a column called order. I don't want gaps. I want 1, 2, 3, 4, 5, .... If i remove 3 then 4 become 3 and 5 becomes 4.
 
I don't want gaps.
Is this column displayed to the user? I would think that it shouldn't be but, if it is, isn't the solution rather obvious? When you remove a row you use a For loop to set the order number of each row.
 
Back
Top