Board index » cppbuilder » Moving items in a TListView with drag and drop
Moving items in a TListView with drag and drop
2004-01-26 03:14:11 AM
I want to give the user the opportunity to move objects in a TListView
with Drag & Drop.
The TListView (lvAula) can be shown both as vsIcons and vsReport
(through a button in the toolbar).
vsReport mode shows additional object's information in columns
MoveItem is called by DragOver after some checks
fromidx and toidx are right.
In vsReport mode it works fine. Icons (and objects) follow mouse drag
and drop operations.
The same code in vsIcon mode doesn't work. Icons keep their position.
Sometimes icons are moved
to the end of the list.
void __fastcall TMyFrame::MoveItem(int fromidx,int toidx)
TListItems * items=lvAula->Items;
if (((fromidx < 0) || (fromidx>items->Count)) ||
((toidx < 0) || (toidx>items->Count)) || (fromidx==toidx))
TListItem * newitem;
selected = items->Item[fromidx]->Selected;
focused = items->Item[fromidx]->Focused;
newitem = items->Insert(toidx + 1);
newitem = items->Insert(toidx);
newitem->Selected = selected;
newitem->Focused = focused;
Any help will be really appreciated.