Board index » cppbuilder » DBGrid, drag'n'drop

DBGrid, drag'n'drop

1) How can I let the user change the order of records in a DBGrid by
drag-and-drop?
2) How can I let the user drag-and-drop records from one DBGrid to
another, i.e. from one underlaying Paradox-table to another?

Thanks in advance!

pv

 

Re:DBGrid, drag'n'drop


Hi, Pv!

The idea of sequentiality is absent from relational databases, which
often use hash tables and other non-linear on disk structures for their
data. Therefore, you must enforce sequentiality by including an
explicit, in-database, sequence number field.

In that case, then, you must identify the record before / after the drop
and adjust the sequence numbers above and below that point and also that
of the dropped record. This can be a complex process. My code to do this
is about a thousand lines.

As for drag and drop between tables, well, you can interpret the dragged
object anyway you want. Let's imagine you have two grids and you allow
drag and drop from one to the other. Each grid uses a different data
source and data set.

If that is the case, the dragged object that will be dropped is the
other grid. You can access the dropped grid's DataSource->DataSet to
determine the current record and (for instance) install its key as a
foreign key in the current record of the destination, or append a record
with that key in the destination data set.

I hope this gives you some ideas. If you have further specific
questions, please post them, and we will all try to help. Some questions
that may arise may get better answers in
borland.public.cppbuilder.database.desktop, so please consider posting
database specific or data aware control specific questions there.

------
Mark Cashman, TeamB C++ Builder
http://www.temporaldoorway.com/programming/index.htm
C++ Builder, JBuilder programming information
Home of The C++ Builder Programmer's Webring - Join us!
------

Re:DBGrid, drag'n'drop


Thank you Mark, that was very useful information. I'm a beginner, and well,
now I'm afraid I've taken the wrong approach in this project. I certainly
don't want to write a thousand lines to enforce sequentiality! Here's what
I'm trying to do:

I have a music database in the form of a Paradox table in which the most
important  fields are: Songtitle, artist, duration in seconds, and path to
the audiofile. I play the songs with TMediaPlayer. I'll have about 1500
records (songs) in the database. Now I want to make a planning tool that
makes it possible for the user to pick songs to be played during, say,  the
next hour. My idea was to make this playlist by drag-and-drop to a new
DBGrid. But it must be possible for the user to change the playing order of
the picked songs.

I tried a string grid in stead of a DBGrid, but I had difficulties
implementing the functionality of TMediaPlayer in this case.

Any suggestions?

PV

Quote
"Mark Cashman (TeamB)" wrote:
> Hi, Pv!

> The idea of sequentiality is absent from relational databases, which
> often use hash tables and other non-linear on disk structures for their
> data. Therefore, you must enforce sequentiality by including an
> explicit, in-database, sequence number field.

> In that case, then, you must identify the record before / after the drop
> and adjust the sequence numbers above and below that point and also that
> of the dropped record. This can be a complex process. My code to do this
> is about a thousand lines.

> As for drag and drop between tables, well, you can interpret the dragged
> object anyway you want. Let's imagine you have two grids and you allow
> drag and drop from one to the other. Each grid uses a different data
> source and data set.

> If that is the case, the dragged object that will be dropped is the
> other grid. You can access the dropped grid's DataSource->DataSet to
> determine the current record and (for instance) install its key as a
> foreign key in the current record of the destination, or append a record
> with that key in the destination data set.

> I hope this gives you some ideas. If you have further specific
> questions, please post them, and we will all try to help. Some questions
> that may arise may get better answers in
> borland.public.cppbuilder.database.desktop, so please consider posting
> database specific or data aware control specific questions there.

> ------
> Mark Cashman, TeamB C++ Builder
> http://www.temporaldoorway.com/programming/index.htm
> C++ Builder, JBuilder programming information
> Home of The C++ Builder Programmer's Webring - Join us!
> ------

Re:DBGrid, drag'n'drop


If you don't need to maintain a database, you can use a TStringGrid, and
save / load the playlist using its LoadFromFile / SaveToFile methods.
There are fairly simple ways to move rows in a TStringGrid, basically by
deleting, copying, and inserting rows. You may find it even easier (if
you don't need multiple columns) to just use a TListBox.

------
Mark Cashman (TeamB - C++ Builder), creator of The Temp{*word*203}Doorway at
http://www.temporaldoorway.com
- Original digital art, writing, music and more -
C++ Builder / JBuilder Tips and The C++ Builder Programmer's Webring
(Join us!)
http://www.temporaldoorway.com/programming/index.htm
------

Re:DBGrid, drag'n'drop


Thanks again, Mark !
PV

Other Threads