C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[22696] Re:리스트뷰 내부에서 드래그 드랍
류현 [rauto] 1051 읽음    2002-11-18 16:45
안녕하세요
아래는 저번 프로그램에 삽입했던 코딩이고요
도움이 되었으면 좋겠네요
멀티로도 선택해서 드레그 할수도 있고요
하나에서 다른 하나로도 이동할수 있어요..
그럼 즐프하세요

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;
}


+ -

관련 글 리스트
22681 리스트뷰 내부에서 드래그 드랍 김성국 731 2002/11/18
22696     Re:리스트뷰 내부에서 드래그 드랍 류현 1051 2002/11/18
22697         Re:Re:리스트뷰 내부에서 /// 현님 감사합니다. 김성국 781 2002/11/18
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.