|
안녕하세요
아래는 저번 프로그램에 삽입했던 코딩이고요
도움이 되었으면 좋겠네요
멀티로도 선택해서 드레그 할수도 있고요
하나에서 다른 하나로도 이동할수 있어요..
그럼 즐프하세요
void __fastcall TForm1::DstListDragDrop(TObject *Sender, TObject *Source,
int X, int Y)
{
int nSelIndex, nCnt=0, nSelCount=0;
TListItem *DestItem;
TListItem *SourceItem;
String InsertItemName, InsertSubItemName;
if(!Sender->ClassNameIs("TListView") || !Source->ClassNameIs("TListView"))
return;
TListView *DestList = (TListView *)Sender;
TListView *SourceList = (TListView *)Source;
//-- 요건 같은 리스트뷰내에서의 이동이고요
if(DestList == SourceList) { //--
nSelIndex = DestList->Selected->Index;
nSelCount = DestList->SelCount;
if(DestList->DropTarget == NULL || DestList->DropTarget->Index == nSelIndex)
return;
for(int i=0; ; i++) {
//-- 요건 멀티로 셀렉트 해서 다시 셀렉트된곳에 놔둘경우에 아래로직을 타서
bpl에러 방지용이고요
if(DestList->DropTarget->Index >= nSelIndex && DestList->DropTarget->Index <= nSelIndex + nSelCount - 1)
return;
if(DestList->Items->Item[nSelIndex+i]->Selected) {
nCnt++;
DestItem = DestList->Items->Item[nSelIndex+i];
InsertItemName = DestItem->Caption;
InsertSubItemName = DestItem->SubItems->Text.TrimRight();
DestList->Items->Delete(nSelIndex+i);
i--;
DestItem = DestList->Items->Insert(DestList->DropTarget->Index+nCnt);
DestItem->Caption = InsertItemName;
DestItem->SubItems->Add(InsertSubItemName.TrimRight());
}
if(nCnt == nSelCount)
break;
}
}
//-- 요건 다른 리스트뷰로의 이동이에요
else if(DestList->Name != SourceList->Name) {
TListItem* Item = ListView2->Selected;
TListItem* InsertItem;
TItemStates selected = TItemStates() << isSelected;
int Index = -1;
while (Item){
//-- 리스트뷰에 최대 허용갯수가 50개로 가정했을경우에
if (DstList->Items->Count >= 50) {
Panel2->Font->Color = clRed;
Panel2->Caption = "최대 50개 까지 가능합니다.";
Beep();
return;
}
if (fnGetIndex(Item->SubItems->Strings[0]) < 0) {
if (Index == -1) {
InsertItem = DstList->Items->Add();
InsertItem->Assign(Item);
}
else {
InsertItem = DstList->Items->Insert(Index);
InsertItem->Assign(Item);
}
}
Item = ListView2->GetNextItem(Item, sdAll, selected);
}
}
}
void __fastcall TForm1::DstListDragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept)
{
Accept = Source->ClassNameIs("TListView");
return;
}
|