I can't speak of DBComponents - don't use them - but you can
accomplish it with a TStringGrid.
Set it's Options property to include goRangeSelect and add an
OnKeyDown event (Ctrl+C) and a Popup Menu.
To perform the Copy, read the grid's Selection property to
know what range of cells have been selected. Iterate through
the cells, getting the text and building a single string that
you will copy to the clipboard.
~ JD
There are components in Transfer@Once (the link below) which support data
transfer to/from both TStringGrid and TDBGrid, as well as sophisticated
selection user interface.
--
Andrei Fomine www.quasidata.com
DbAltGrid - multi-line layout, RTF and graphics of any kind in DBGrid.
Transfer@Once - full-blown clipboard and drag-and-drop data transfer to/from
any control in many formats, including ones native to MS Office.
"Marcio Ehrlich" <nou...@nouser.com> wrote in message
news:3ffa...@newsgroups.borland.com...
StringGrid allowed this kind of selection using shift-arrows. Maybe to use
the mouse I would have to write some special code, but I am not sure of
which event I should detect.
DBGrid, with goRangeSelect =True only allowed me to select entire rows, not
a range of cells.
I guess Database Desktop was not written in Delphi.
Marcio
it is not very complicated.
Var
S: String;
i, k: Integer;
begin
S:= '';
with stringgrid1 do begin
for i:= FixedRows to RowCount-1 do begin
For k:= FixedCols to ColCOunt-1 do begin
If k > FixedCols Then
S:= S + #9;
S:= S + Cells[k,i];
end; { for }
S:= S + #13#10;
end; { for }
end; { with }
Clipboard.AsText := S;
This generates a string in which columns are separated by Tab characters
and rows by CR/LF linebreaks. Most spreadsheets are able to paste this into
cells correctly.
Same for the selection in a grid:
S:= '';
With grid do
for i:= Selection.Top to Selection.Bottom do begin
for k:= Selection.Left to Selection.Right Do begin
S:= S + Cells[k,i];
If k <> Selection.Right Then
S := S + #9;
end;
S:= S + #13#10;
end;
Clipboard.AsText := S;
--
Peter Below (TeamB)
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be
Peter,
Thank you, but you only gave the second part of the question, about copying
to the clipboard.
Before that I need to select the range of cells with the mouse like Database
Desktop allows and I could not find how to do it with data from a table.
Marcio
The code i posted only works for a TStringgrid, not for a TDBGrid. The latter
requires a totally different approach, since it is a virtual grid, a view into
a dataset. The grid just has enough physical rows to cover its visible space,
the rows get reused for other records when you scroll through the dataset.
Selected items in a TDBGrid are identified by bookmarks, as far as i remember.
I rarely use databound controls, they simply do not fit my style of writing
apps. You would iterate over the SelectedRows property of the grid, which is a
list if bookmarks, for each use the associated datasets GotoBookmark method to
locate the associated record, and fetch the field values from the dataset (not
the grid) and assemble them into the string you want to put on the clipboard.