Mega Search
23.2 Million


Sign Up

Make a donation  
FMX.TListBox / TListboxItem drag drop [Edit]  
News Group: embarcadero.public.delphi.oodesign

Hi,

I have code in VCL that allows drag and drop between 2 listboxes for selections (better than checkboxes when you have larger lists) and also because the order in the listbox is important.  What is the procedure for dragging a listboxitem from one listbox to the other?  Also how to reposition a listboxitem in the same listbox?  Accept parameter appears absent from FMX and instead there seems to be a TDragOperation in its place.

Here is how I do this the VCL code:



procedure TFormOptions.LBFloatDragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if Source is TListBox then
    Accept := True
  else
    Accept := False;
end;

procedure TFormOptions.LBFloatDragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  TransferItems(Sender, Source);
end;

procedure TFormOptions.TransferItems(Sender, Source: TObject);
var
  I: Integer;
begin
  with (Source as TListBox) do
  begin
    for I := 0 to Items.Count - 1 do
      if Selected[I] then
        (Sender as TListBox).Items.Add(Items[I]);

        for I := Items.Count - 1 DownTo 0 do
          if Selected[I] then
          	Items.Delete(I);
  end;
end;



Sincerely
Curtis Manwaring

Edited by: Curtis Manwaring on Jan 15, 2015 5:02 PM

Vote for best question.
Score: 0  # Vote:  0
Date Posted: 15-Jan-2015, at 5:03 PM EST
From: Curtis Manwaring
 
Re: FMX.TListBox / TListboxItem drag drop [Edit]  
News Group: embarcadero.public.delphi.oodesign
Never mind.  I figured it out.

In case anyone is interested...

{code}

procedure TFormTransfer.TransferItems(Sender, Source: TObject);
var
  I: Integer;
begin
  with (Source as TListBox) do
  begin
    for I := 0 to Items.Count - 1 do
      if ListItems[I].IsSelected then
        (Sender as TListBox).Items.Add(ListItems[I].Text);

    for I := Items.Count - 1 downto 0 do
      if ListItems[I].IsSelected then
        Items.Delete(I);
  end;
end;

{code}

Edited by: Curtis Manwaring on Jan 17, 2015 3:02 PM

Vote for best answer.
Score: 0  # Vote:  0
Date Posted: 17-Jan-2015, at 3:04 PM EST
From: Curtis Manwaring