re-ordering rows/records

G

Guest

Any good routines or suggestions to assist me in re-ordering my records in my
datagrid?

i.e. I have a field in each record that is used for ordering (i.e. 1,2,3,4).
I would like to implement a set of options to move the record up one, down
one, move to top, move to bottom of this order. Thus changing that field
values, and the others in the table.

so then I can sort based on that field to order the values.
Using SQl server as backend. Frame 1.1

thanx.
 
E

Eliyahu Goldin

Likely you want to do this on server side. Get buttons click events, get the
grid's selected item and reorganize the datatable. It is easier to update
the table if you make order values in units of thousands, like 1000, 2000,
3000 rather than 1, 2, 3. Then, when you move a record, you just set its
order value between the neighbor record ones and there is no need to change
all other records.

Eliyahu
 
G

Guest

thanx!
Eliyahu Goldin said:
Likely you want to do this on server side. Get buttons click events, get the
grid's selected item and reorganize the datatable. It is easier to update
the table if you make order values in units of thousands, like 1000, 2000,
3000 rather than 1, 2, 3. Then, when you move a record, you just set its
order value between the neighbor record ones and there is no need to change
all other records.

Eliyahu
 
G

Guest

I've set it up this way, any ideas on preventing dup vlaues? My routine has
the added level of complexity of move to top or move to bottom. But I thought
thta if I set the value, for example, +2 for the move item and -2 for the
original item that I'd be safe. I get dup values.

i.e.
1000
2000
3000
4000
5000

move 5000 to top, now item = 998 (-2) and the original item is 1002 (+2).But
sometimes I end up with:
944
946
950
950

how can you move by 1000's? If you set to a value between you would go:
500
1000
2000
3000
and eventually run out of space????????
 
E

Eliyahu Goldin

First, like you say at the end, set to a value in between. Also you can
start form 100000, 200000 etc. This will give you more room. Second, when
you find the new number is already taken reset the numbers for all records
to 100000, 200000. You can make a stored procedure to do it on the database
server.

This is just first what comes to my mind. Sure you can find more advanced
algorithms.

Eliyahu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top