Jump to content

how to Drag and Drop from TUniDBGrid to TUniStringGrid


rhennink

Recommended Posts

  • 1 year later...
On 11/16/2020 at 10:34 PM, rhennink said:

Hi,

I checked the forums, but cannot find anything working about this, but..

How can I implement drag & drop on a StringGrid.

I would like to drag some data from a DBGrid to a cell (converted) in a StringGrid.

Thnx!

Richard

 

Hello, You can use standard method to copy data from cells in dbGrid and after drop on StringGrid just Paste clipboard with data.

this is how to copy in clipboard:

uses Clipbrd;

var

sData : String;

 

//copy to Clipboard if is used [Ctrl + Left]
If Shift = [ssCtrl] then begin
 Clipboard.AsText := TDBgrid (Sender).Columns [TDBgrid (Sender).SelectedIndex].Field.AsString;
end;

//copy to clipboard all selected rows if [ctrl + shift]
if shift = [ssCtrl,ssShift] then begin
 sData := '';
 //set column's name
 for I := 0 to TDBgrid (Sender).Columns.Count - 1 do begin
    if TDBgrid (Sender).Columns[I].Visible then begin
      sData := sData + TDBgrid (Sender).Columns[I].Title.Caption;

      if I < (TDBgrid (Sender).Columns.Count - 1) then
        sData := sData + #9;
    end;
 end;
 sData := sData + #13#10;

 //read all data
 for J := 0 to TDBgrid (Sender).SelectedRows.Count - 1 do begin
     TDBgrid (Sender).DataSource.DataSet.GotoBookmark (TBookmark(TDBgrid (Sender).SelectedRows[J]));
     for I := 0 to TDBgrid (Sender).Columns.Count - 1 do begin
        if TDBgrid (Sender).Columns[I].Visible then begin
          if TDBgrid (Sender).Columns[I].Field <> nil then
            sData := sData + TDBgrid (Sender).Columns[I].Field.asString
          else sData := sData + '';

          if I < (TDBgrid (Sender).Columns.Count - 1) then
            sData := sData + #9;
        end;
     end;
     sData := sData + #13#10;
 end;
 Clipboard.setTextBuf(PCHAR (sData));
end;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...