Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Listview Drag Into Group

Posted on 2009-05-14
1
Medium Priority
?
679 Views
Last Modified: 2012-05-07
Hi, I'd liketo me able to Drag a listview item into a listview Group

for example I have 2 groups, I grad 1 item into the second group

this is what I'm using for dragging.

procedure TFrame2.ListView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  currentItem, nextItem, dragItem, dropItem : TListItem;
begin
  if Sender = Source then
  begin
    with TListView(Sender) do
    begin
      dropItem := GetItemAt(X, Y) ;
      currentItem := Selected;
      while currentItem <> nil do
      begin
        nextItem := GetNextItem(currentItem, SdAll, [IsSelected]) ;
        if Assigned(dropItem) then
          dragItem := Items.Insert(dropItem.Index)
        else
          dragItem := Items.Add;
        dragItem.Assign(currentItem) ;
        currentItem.Free;
        currentItem := nextItem;
      end;
    end;
  end;

end;

procedure TFrame2.ListView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  Accept := Sender = ListView1;
end;





and from what I can tell this is for changing the item to a different group. the below will move the selected item into the second group.

listview1.Items.Item[listview1.Selected.Index].GroupID:=1;



I'm needing that to be merged within the drag.


there is also this function

function MoveListViewItem(ListView: TListView; ItemFrom, ItemTo: Word): Boolean;
var
  Source, Target: TListItem;
begin
  listview.Items.BeginUpdate;
  try
    Source := ListView.Items[ItemFrom];
    Target := ListView.Items.Insert(ItemTo);
    Target.Assign(Source);
    Target.Selected := True;
    Source.Free;
    Result := True;
  finally
    ListView.Items.EndUpdate;
  end;
end;
 
//Move Down
 if ListView1.Selected <> nil then
  MoveListViewItem(ListView1, ListViewIP1.Selected.Index, ListView1.Selected.Index + 2);
 
//Move Up
 if ListView1.Selected <> nil then
  MoveListViewItem(ListView1, ListView1.Selected.Index, ListView1.Selected.Index -1);


0
Comment
Question by:eNarc
1 Comment
 
LVL 26

Accepted Solution

by:
EddieShipman earned 2000 total points
ID: 24396565
Can't you just check the GroupID of dropItem and then set the GroupID of dragItem to the same?
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Integration Management Part 2
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question