在编写某个系统时,由于使用了数据集类型无关技术(即数据集可能是ADOQuery,也有可能是TClientDataSet等等)。当需要对数据进行排序和查找时,只好利用cxGrid自身的功能来实现:
function GridSortColumn(View : TcxGridDBTableView; FieldName : String) : Boolean;
var
i : Integer;
begin
{数据排序}
Result := False;
for i := 0 to View.ColumnCount -1 do
begin
if (UpperCase(View.Columns[i].DataBinding.FieldName) = FieldName) then
begin
View.Columns[i].SortIndex := 0;
View.Columns[i].SortOrder := soAscending;
Result := True;
end
else
begin
View.Columns[i].SortIndex := -1;
View.Columns[i].SortOrder := soNone;
end;
end;
end;
function GridLocateRecord(View : TcxGridDBTableView; FieldName, LocateValue : String) : Boolean;
begin
{数据查找}
Result := False;
if (View.GetColumnByF
本文介绍了在Delphi开发中,如何利用CxGrid组件进行数据集的排序和查找。提供了两个函数,GridSortColumn用于按指定字段升序排序,GridLocateRecord则用于快速定位特定记录。注意在排序后,应避免直接使用数据集的Next和Prior操作,而应改用调整FocusedRowIndex的方式来浏览记录,以防止记录顺序混乱。
订阅专栏 解锁全文

1964

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



