Solved

Listview Drag Into Group

Posted on 2009-05-14
1
630 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 500 total points
Comment Utility
Can't you just check the GroupID of dropItem and then set the GroupID of dragItem to the same?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
loading dll from external path 1 195
Magic Software info 18 100
delphi parse string to params 3 79
Reconfigure Delphi Install? 2 34
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now