Link to home
Start Free TrialLog in
Avatar of gulki
gulki

asked on

RowMove within a DBGrid

Hi to all experts

Does someone know a possibility to move a row within a dbgrid with the mouse (like columnmove).

The thing is, that I have a column called "position" with represents the sortorder of the query ! My question is now, if there is a possibility, that a user can move a row (position) with the mouse, and if he has done so, a function automatically changes in the database the values of the field position depending on the new order now !


Thanks
Avatar of kretzschmar
kretzschmar
Flag of Germany image

hi gulki,
you must "move" (adjust the positionsvalue) in your table.

therefore there is no way to do it first in the grid and then in the table, its more first do it in the table and the grid recogize the change

can provide a sample in some hours

meikl
Hi gulki, Meikl,

Drag & Drop will not help in this case?

-----
Igor.



hi igor,

yes, i've ignored the drag&drop for now,
(but i guess, i have also a solution for this), because first is to implement a "recordmove" in the underlying dataset, which is not to hard and which i have already done sometimes ago.

meikl ;-)
Ok, meikl.
I have too. Let you first;)
----
Igor
hi igor,

you must not wait,
also i'm interesting
how you it implements.

meikl
hi meikl,
litle bit later, I'm still trying to help
https://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10347920 

Igor.
Hi qulki,
There is the way how to change order of records in database table. Let suppose you have a table where "RCN" field is sortorder.

RCN  DATA
 1     aaa
 2     bbb
 3     ccc
 4     ddd
 5     eee
 6     fff

And you need to move record "5 eee" to top, between "3 ccc" and "2 bbb".

1.  hide record
SQL> update thetable set RCN=0 where RCN=5

2.  make hole after "2 bbb" and increase sortorder to other records
SQL> update thetable set RCN=RCN+1 where RCN>2 and RCN<5

3. place to desired position
SQL> update thetable set RCN=3 where RCN=0


in most cases:
OLDPOS - old value of RCN
NEWPOS - new value of RCN

update thetable set RCN=0 where RCN=:OLDPOS
update thetable set RCN=RCN+1 where RCN>:NEWPOS-1 and RCN<:OLDPOS
update thetable set RCN=:NEWPOS where RCN=0




----
Igor.
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
just to remark,

if you have a live query then you can replace table1 with your query,
if it not a live query then you must do it like Igor comments
(three update-sql-statements) and
close and reopen your original query after the action

meikl
Avatar of gulki
gulki

ASKER

Hi Folks

I am now triying your proposals. In a few days I will tell you, if it worked or not !

thanks in advance
Avatar of gulki

ASKER

Thanks a lot folks

You helped me a lot. And I think, that the prototype-solution of kretzschmar has earned the points, even if igor had an idea how to change the order, but the question was a drag&drop.

Thanks
just accept the comment as answer, which helps you mostly ;-)
glad, that you like it
hi qulki,
meikl did a big work for you, of course you should accept his comment as answer;)
----
Igor
Avatar of gulki

ASKER

Comment accepted as answer
Avatar of gulki

ASKER

It was a really excellent job !

Thank you kretzschmar , you really earned the points