the Code is used for when you click the title of the DBGrid it can sorting by itself...
First , add some define...
TField *FSortField;
void __fastcall SetSortField(TField *Value);
__property TField *SortField = {read=FSortField,write=SetSortField};
then , add the code in the event——the OnTitleClick of the DBGrid...
void __fastcall TForm1::DBGrid1TitleClick(TColumn *Column)
{
SortField = Column->Field;
}
the last , construct the function named SetSort...
void __fastcall TForm1::SetSortField(TField *Value)
{
static bool DescSort = false;
try {
Screen->Cursor = crHourGlass;
if (FSortField != NULL) {
AnsiString label = FSortField->DisplayLabel;
FSortField->DisplayLabel = label.SubString(1,label.Length()-3); //删除尾部排序字符
}
if (FSortField == Value)
DescSort = !DescSort;
ADOTable1->Sort = Value->FieldName + " " + (DescSort?"DESC":"ASC");
Value->DisplayLabel = Value->DisplayLabel + (DescSort?" -":" +");
FSortField = Value;
}
__finally {
Screen->Cursor = crDefault;
}
}
End...