//
// 使用说明:单击DBGridEh的标题栏排序(适用于ADO)
// --在DBGridEh的事件OnTitleBtnClick引用该函数即可:
// SortDBGridEh(Sender, ACol, Column);
// --为了保证表格的每一列都能点击触发排序,你需要将你需要排序的列属性
// -- Title->TitleButton设置为True。
//
procedure SortDBGridEh(Sender: TObject; ACol: Integer; Column: TColumnEh);
var
FieldName, SortStr: string;
begin
Screen.Cursor := crSQLWait;
try
if (Sender is TDBGridEh) and
((Sender as TDBGridEh).DataSource.DataSet <> nil) then
begin
if not ((Sender as TDBGridEh).DataSource.DataSet is
TCustomADODataSet) then
Exit;
if not (Sender as TDBGridEh).DataSource.DataSet.Active then
Exit;
FieldName := Column.FieldName;
if (Sender as
TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob then
Exit;
if (Sender as
TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkData then
SortStr := FieldName
else if (Sender as
TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkLookup then
FieldName := (Sender as TDBGridEh).DataSource.DataSet.FieldByName
(FieldName).KeyFields
else
FieldName := '';
if (FieldName = '') or (Pos(';', FieldName) > 0) then
Exit;
case Column.Title.SortMarker of
smNoneEh:
begin
Column.Title.SortMarker := smUpEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort :=
FieldName;
end;
smUpEh:
begin
Column.Title.SortMarker := smDownEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort :=
FieldName + ' DESC';
end;
smDownEh:
begin
Column.Title.SortMarker := smNoneEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort := '';
end;
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;
// 使用说明:单击DBGridEh的标题栏排序(适用于ADO)
// --在DBGridEh的事件OnTitleBtnClick引用该函数即可:
// SortDBGridEh(Sender, ACol, Column);
// --为了保证表格的每一列都能点击触发排序,你需要将你需要排序的列属性
// -- Title->TitleButton设置为True。
//
procedure SortDBGridEh(Sender: TObject; ACol: Integer; Column: TColumnEh);
var
FieldName, SortStr: string;
begin
Screen.Cursor := crSQLWait;
try
if (Sender is TDBGridEh) and
((Sender as TDBGridEh).DataSource.DataSet <> nil) then
begin
if not ((Sender as TDBGridEh).DataSource.DataSet is
TCustomADODataSet) then
Exit;
if not (Sender as TDBGridEh).DataSource.DataSet.Active then
Exit;
FieldName := Column.FieldName;
if (Sender as
TDBGridEh).DataSource.DataSet.FindField(FieldName).IsBlob then
Exit;
if (Sender as
TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkData then
SortStr := FieldName
else if (Sender as
TDBGridEh).DataSource.DataSet.FieldByName(FieldName).FieldKind =
fkLookup then
FieldName := (Sender as TDBGridEh).DataSource.DataSet.FieldByName
(FieldName).KeyFields
else
FieldName := '';
if (FieldName = '') or (Pos(';', FieldName) > 0) then
Exit;
case Column.Title.SortMarker of
smNoneEh:
begin
Column.Title.SortMarker := smUpEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort :=
FieldName;
end;
smUpEh:
begin
Column.Title.SortMarker := smDownEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort :=
FieldName + ' DESC';
end;
smDownEh:
begin
Column.Title.SortMarker := smNoneEh;
TCustomADODataSet((Sender as
TDBGridEh).DataSource.DataSet).Sort := '';
end;
end;
end;
finally
Screen.Cursor := crDefault;
end;
end;
博客介绍了使用DBGridEh标题栏排序的方法,适用于ADO。需在DBGridEh的OnTitleBtnClick事件引用SortDBGridEh函数,同时将需排序列的Title->TitleButton属性设为True。还给出了SortDBGridEh函数的具体实现代码。
574

被折叠的 条评论
为什么被折叠?



