|
안녕하세요 utime.김성하입니다.
정답이 될 지 모르겠지만 저는 요렇게 사용합니다.
그냥 참고만 하시길 바랍니다~ ^^*
int SelColNum = 1;
int Ascend = 1;
void __fastcall TForm1::ListView1ColumnClick(TObject *Sender,
TListColumn *Column)
{
SelColNum = Column->Index;
Ascend = -Ascend;
((TListView*)Sender)->AlphaSort();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ListView1Compare(TObject *Sender, TListItem *Item1,
TListItem *Item2, int Data, int &Compare)
{
AnsiString S1, S2;
Compare = 0;
switch( SelColNum )
{
case 0: // 숫자
S1.sprintf("%4d", Item1->Caption.ToInt());
S2.sprintf("%4d", Item2->Caption.ToInt());
break;
case 1 : // 숫자
S1.sprintf("%4d", Item1->SubItems->Strings[SelColNum-1].ToInt());
S2.sprintf("%4d", Item2->SubItems->Strings[SelColNum-1].ToInt());
break;
case 2 : // 문자열
S1 = Item1->SubItems->Strings[SelColNum-1];
S2 = Item2->SubItems->Strings[SelColNum-1];
break;
default :
Compare = 0;
}
Compare = CompareText(S1,S2) * Ascend;
}
//---------------------------------------------------------------------------
freeman 님이 쓰신 글 :
: ^^ 안녕하세요 리스트 뷰에서 컬럼헤더를 클릭시 소팅시 아래와 같은 코드에서는알파벳 순 소팅만
: 합니다. 특정 컬럼의 값이 숫자일 때는 OnCompare에서 어떻게 수정해야 하나요
: 여러 고수님의 고견을 부탁 드립니다.
:
: int SortByColumn = -1;
: int SortOrder = 1;
: //---------------------------------------------------------------------------------
: void __fastcall TForm1::ListView1Compare(TObject *Sender, TListItem *Item1,
: TListItem *Item2, int Data, int &Compare)
: {
:
: if(Data == 0)
: {
: if(Item1->Caption < Item2->Caption) Compare = -1;
: else if(Item1->Caption > Item2->Caption) Compare = 1;
: else Compare = 0;
: }
: else
: {
: if(Item1->SubItems->Strings[Data-1] < Item2->SubItems->Strings[Data-1]) Compare = -1;
: else if(Item1->SubItems->Strings[Data-1] > Item2->SubItems->Strings[Data-1]) Compare = 1;
: else Compare = 0;
: }
: Compare *= SortOrder;
:
: }
: //---------------------------------------------------------------------------
:
: void __fastcall TForm1::ListView1ColumnClick(TObject *Sender,
: TListColumn *Column)
: {
: if(SortByColumn == Column->Index) SortOrder *= -1;
: else SortOrder = 1;
: ListView1->CustomSort(NULL, Column->Index);
: SortByColumn = Column->Index;
:
: }
: //---------------------------------------------------------------------------
|