Sort前
---------------------------------------------
Sort後
---------------------------------------------
細節部份在自行調整.
//--------------------------------------------------------------------------- #include
#pragma hdrstop #include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::TreeView1Compare(TObject *Sender, TTreeNode *Node1,
TTreeNode *Node2, int Data, int &Compare)
{
if ((Node1->HasChildren && Node2->HasChildren) ||
(!Node1->HasChildren && !Node2->HasChildren))
{
// 當兩個Node均有Child或均無Child, 則以兩者的文字比較
Compare = strcmp(Node1->Text.c_str(), Node2->Text.c_str());
}
else if ((Node1->HasChildren) && (!Node2->HasChildren))
{
// 當Node1有Child, Node2沒有Child, 則把Node2放後面
Compare = -1;
}
else if ((!Node1->HasChildren) && (Node2->HasChildren))
{
// 當Node1沒有Child, Node2有Child, 則把Node1放後面
Compare = 1;
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
TreeView1->AlphaSort();
}
//---------------------------------------------------------------------------