Jump to content


Photo

How to move Childrow with Drag/drop in NextGrid?

moveto move childrow moveto rows

  • Please log in to reply
3 replies to this topic

#1 bicks

bicks
  • Members
  • 8 posts

Posted 12 February 2022 - 01:42 PM

Hi Boki,
 
I'm just trying to manage some groups and subgroups, but got difficulties;
 
I use a NextGrid with an TnxTreeColumn and some rows and childrows.

I'd like to move with DragDrop mouse, the selected row to different position.

e.g. Row 'Sub child 3' to be slave to 'master'.

 

How to determinate the Destination ROW in DragDrop event?

What value need to have argument Index to make source row child and put it as last child row of child list?

nextgrid61.Row[nextgrid61.SelectedRow].MoveTo(????,0);

for example TTreeview has function GetNodeAt(X, Y: Integer). is any similar function in Nextgrid?

 

Here is my code

procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
nextgrid61.AddCells(['MASTER','0','1'],[0,1,2]);
for i := 1 to 3 do
 with nextgrid61.AddChildRow(0,1) do
  cells.Item[0].AsString:='Child '+inttostr(i);
for i := 1 to 3 do
  with nextgrid61.AddChildRow(2,1) do
      cells.Item[0].AsString:='Sub-Child '+inttostr(i);
for i := 1 to 3 do
  with nextgrid61.AddChildRow(6,1) do
      cells.Item[0].AsString:='Sub-baby '+inttostr(i); 
end;
 
procedure TForm1.NextGrid61DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
 nextgrid61.Row[nextgrid61.SelectedRow].MoveTo('????',0);
end;
 
procedure TForm1.NextGrid61MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if (Button = mbLeft) and not (ssDouble in Shift) then
      nextgrid61.BeginDrag(FALSE, 5);
end;

Best Regards

Bicks



#2 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 12 February 2022 - 10:09 PM

Hello,

 

I will test your code and write you here what is needed to do drag and drop.

 

I hope that I will have it for tomorrow.


boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.

#3 bicks

bicks
  • Members
  • 8 posts

Posted 15 February 2022 - 11:50 AM

Hi Boki, 

 

I saw an example about drag and drop rows with Treecolumn in Demo examples.

Code in the example uses Rowmoving Properties which is convinient in common cases, but

it has some limitations that make it useless for me.(e.g. it doesn't raise any events to handle it).

 

Waiting for your help. 

 

Best Regards

Bicks



#4 Boki (Berg)

Boki (Berg)

    Boki (Berg)

  • Forum Admin
  • PipPipPipPipPip
  • 8,191 posts
  • Gender:Male

Posted 16 February 2022 - 08:04 PM

Hello,

 

Sorry for small delay,

 

This is the first version I made. I will need to add few more checkings and make moving to root. I think that I will make it as a new demo project:

 

unit Unit2;
 
interface
 
uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, NxGridView6, NxColumns6,
  NxControls6, NxCustomGrid6, NxVirtualGrid6, NxGrid6;
 
type
  TForm2 = class(TForm)
    NextGrid61: TNextGrid6;
    NxTreeColumn61: TNxTreeColumn6;
    NxReportGridView61: TNxReportGridView6;
    Button1: TButton;
    NxTextColumn61: TNxTextColumn6;
    NxTextColumn62: TNxTextColumn6;
    procedure Button1Click(Sender: TObject);
    procedure NextGrid61MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure NextGrid61DragDrop(Sender, Source: TObject; X, Y: Integer);
    procedure NextGrid61DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
  private
    { Private declarations }
    FDraggingIndex: Integer;
  public
    { Public declarations }
  end;
 
var
  Form2: TForm2;
 
implementation
 
uses
  NxCells6;
 
{$R *.dfm}
 
procedure TForm2.Button1Click(Sender: TObject);
var
  i: Integer;
begin
  NextGrid61.AddCells(['MASTER', '0', '1'], [0, 1, 2]);
  for i := 1 to 3 do
    with NextGrid61.AddChildRow(0, 1) do
      cells.Item[0].AsString := 'Child ' + inttostr(i);
  for i := 1 to 3 do
    with NextGrid61.AddChildRow(2, 1) do
      cells.Item[0].AsString := 'Sub-Child ' + inttostr(i);
  for i := 1 to 3 do
    with NextGrid61.AddChildRow(6, 1) do
      cells.Item[0].AsString := 'Sub-baby ' + inttostr(i);
end;
 
procedure TForm2.NextGrid61DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  RowIndex: Integer;
  NewParent: INxRow;
begin
  RowIndex := NextGrid61.ActiveView.GetCellAtPos(Point(X, Y)).Y;
  NewParent := nil;
  if (RowIndex >= 0) and (RowIndex < NextGrid61.RowCount) then
  begin
    NewParent := NextGrid61.Row[RowIndex];
    NextGrid61.Row[FDraggingIndex].MoveTo(NewParent);
    FDraggingIndex := -1;
    NextGrid61.Invalidate;
  end;
end;
 
procedure TForm2.NextGrid61DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
var
  RowIndex: Integer;
begin
  RowIndex := NextGrid61.ActiveView.GetCellAtPos(Point(X, Y)).Y;
  Accept := (RowIndex >= 0) and (RowIndex < NextGrid61.RowCount);
end;
 
procedure TForm2.NextGrid61MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  RowIndex: Integer;
begin
  RowIndex := NextGrid61.ActiveView.GetCellAtPos(Point(X, Y)).Y;
  if (RowIndex >= 0) and (RowIndex < NextGrid61.RowCount) then
  begin
    FDraggingIndex := RowIndex;
    NextGrid61.BeginDrag(False, 4);
  end;
end;
 
end.

boki@bergsoft.net | LinkedIn Profile
--
BergSoft Home Page: www.bergsoft.net
Users Section: users.bergsoft.net
Articles and Tutorials: help.bergsoft.net (Developers Network)
--
BergSoft Facebook page
--
Send us applications made with our components and we will submit them on: www.bergsoft.net/apps.htm. Link to this page will be also set on home page too.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users