Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 20 total
Thread Allowing User to Changing the Order of Records
Mon, Feb 6 2006 9:16 PMPermanent Link

"Adam H."
Hi,

I'm needing to develop a routine where a user can rearrange the order of the
records that are displayed on a screen. The records in question are a
packing schedule, when certain items will be packed. The user needs the
ability to drag and drop to change the order of each record.

I was thinking of the following approach, but don't know if this is the best
idea, or if their is another 'standard' way of achieving the same result.

In my instance, I was going to have a float field that automatically
increased by a value of 1 everytime a record was entered. Then, if a user
went to drag a record to a new location, all I would need to do is find the
value of the record before it, and the value of the record after it, and
change the 'active' records value to half way between these values.

ie - with the following data:

1 - Apples
2 - Pears
3 - Oranges
4 - Pineapples

If the user wanted to have Pineapples first, I would change the Pineapple
value to 1.5, thus giving

1.0 - Apples
1.5 - Pineapples
2.0 - Pears
3.0 - Oranges

That way, if I decided to later put something between Apples and Pineapples,
I could arrange it as 1.25, and so on and so on, without having to change
the 'sort' values of every record.

Is this approach OK to use, or is there a better way?

Thanks & Regards

Adam.

Tue, Feb 7 2006 5:58 AMPermanent Link

Neat idea.  I've been doing the same with integers with gaps, but once
the gap has been used it requires the numbers to be re-assigned ready for the
next drag and drop.

--Bill Sparrow--

Tue, Feb 7 2006 8:11 AMPermanent Link

=?iso-8859-15?Q?Andr=E9_Prins?=
Adam H. wrote:

> Is this approach OK to use, or is there a better way?

Depending on the number of records shown you can also implement up/down buttons and/or keys. That way the values only need to be
swapped and rearranging can go on forever. Drag and drop is not possible though.

--
André Prins
Twain Development
Tue, Feb 7 2006 2:42 PMPermanent Link

"Adam H."
Hi Bill,

> Neat idea.  I've been doing the same with integers with gaps, but once
> the gap has been used it requires the numbers to be re-assigned ready for
the
> next drag and drop.

Thanks for the compliment. I thought of a similar approach to yours, but
didn't want to have to re-assign values every time the user moves a record.

I actually expected a "No no... that's not the way to do it, the best way
is.....", but maybe there isn't a 'standard' to this.

Best Regards

Adam.

Tue, Feb 7 2006 2:43 PMPermanent Link

"Adam H."
Hi André,

> > Is this approach OK to use, or is there a better way?
>
> Depending on the number of records shown you can also implement up/down
buttons and/or keys. That way the values only
> need to be swapped and rearranging can go on forever. Drag and drop is not
possible though.

Thanks for the suggestion. I have used the up/down arrows in the past to
'swap records', however in this scenario records could be moved my more than
20 rows each time, and a drag/drop solution will be much better for the end
user IMO.

Best Regards

Adam.

Tue, Feb 7 2006 3:12 PMPermanent Link

Adam;
Create an indexed field "autoinc" in your table. Here it is "OrderID"
I used this code and it works like a dream ( freely - borrowed  from dbsys)
put the TUpDown Component on your form.


procedure TForm1.UpDown1ChangingEx(Sender: TObject;
   var AllowChange: Boolean; NewValue: Smallint;
   Direction: TUpDownDirection);
var
   OldPosition: Integer;
begin
   Rooms.CheckBrowseMode;

   try
       with Rooms do
       begin
           DisableControls;
           try
               if (Direction = updUp) then
               begin
                   if (Rooms.FieldByName('OrderID').AsInteger > 1) then
                   begin
                       OldPosition :=
Rooms.FieldByName('OrderID').AsInteger;
                       Prior;
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
High(Integer);
                       Post;
                       FindKey([OldPosition]);
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
(OldPosition - 1);
                       Post;
                       FindKey([High(Integer)]);
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
OldPosition;
                       Post;
                       FindKey([(OldPosition - 1)]);
                   end;
               end
               else
               begin
                   if (Rooms.FieldByName('OrderID').AsInteger <
RecordCount) then
                   begin
                       OldPosition :=
Rooms.FieldByName('OrderID').AsInteger;
                       Next;
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
High(Integer);
                       Post;
                       FindKey([OldPosition]);
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
(OldPosition + 1);
                       Post;
                       FindKey([High(Integer)]);
                       Edit;
                       Rooms.FieldByName('OrderID').AsInteger :=
OldPosition;
                       Post;
                       FindKey([(OldPosition + 1)]);
                   end;
               end;
           finally
               EnableControls;
           end;
       end;
   finally

   end;

end;
"Adam H." <ahairsub4@rREMOVEMEspamSTOPPER.jvxp.com> wrote in message
news:6BD90D0D-5BE1-461A-90B7-F2ADBA232C21@news.elevatesoft.com...
> Hi André,
>
> > > Is this approach OK to use, or is there a better way?
> >
> > Depending on the number of records shown you can also implement up/down
> buttons and/or keys. That way the values only
> > need to be swapped and rearranging can go on forever. Drag and drop is
not
> possible though.
>
> Thanks for the suggestion. I have used the up/down arrows in the past to
> 'swap records', however in this scenario records could be moved my more
than
> 20 rows each time, and a drag/drop solution will be much better for the
end
> user IMO.
>
> Best Regards
>
> Adam.
>
>

Tue, Feb 7 2006 5:12 PMPermanent Link

"Adam H."
Hi Brock,

> Create an indexed field "autoinc" in your table. Here it is "OrderID"
> I used this code and it works like a dream ( freely - borrowed  from
dbsys)
> put the TUpDown Component on your form.

<Snip>

Thanks for your post. However, doesn't this just move the record one space
at a time? I'm hoping to have somethign that will allow me to jump 20
records in one go using drag and drop on a grid.

Cheers

Adam.

Tue, Feb 7 2006 5:52 PMPermanent Link

=?iso-8859-15?Q?Andr=E9_Prins?=
Adam H. wrote:

> Thanks for the suggestion. I have used the up/down arrows in the past to
> 'swap records', however in this scenario records could be moved my more than
> 20 rows each time, and a drag/drop solution will be much better for the end
> user IMO.

If that is the case I'd use an integer with an interval of 10000. Gives you plenty of room to shuffle the records.

10000
20000
30000
40000

10000
15000
20000
30000

10000
12500
15000
20000

etc.

--
André Prins
Twain Development
Tue, Feb 7 2006 6:33 PMPermanent Link

"Adam H."
Hi André Prins,

> If that is the case I'd use an integer with an interval of 10000. Gives
you plenty of room to shuffle the records.

Would there be any benefit in using this method, say over my float method?
Are working with floats the way I am a concern, or is it essentially doing
the same thing?

Thanks & Regards

Adam.

Tue, Feb 7 2006 7:54 PMPermanent Link

=?iso-8859-15?Q?Andr=E9_Prins?=
Adam H. wrote:

> Are working with floats the way I am a concern, or is it essentially doing
> the same thing?

Hi Adam,

It is essentially the same, but I use integers for this kind of functionality, because it's supported in all programming
environments and databases I use and I also find it easier to read the integers than the floats.

HTH

--
André Prins
Twain Development
Page 1 of 2Next Page »
Jump to Page:  1 2
Image