Delphi中使用cxGrid对数据集进行Sort和Locate操作
2012-11-02 08:28
495 查看
Delphi中使用cxGrid对数据集进行Sort和Locate操作
核心提示:在编写某个系统时,由于使用了数据集类型无关技术(即数据集可能是ADOQuery,也有可能是TClientDataSet等等)。当需要对数据进行排序和查找时,只好利用cxGrid自身的功能来实现:fun...在编写某个系统时,由于使用了数据集类型无关技术(即数据集可能是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.GetColumnByFieldName(FieldName) <> nil) then
Result := View.DataController.Search.Locate(View.GetColumnByFieldName(FieldName).Index, LocateValue);
end;
对于cxGrid排序后的数据集,不应该进行Next, Prior等操作,因为数据集的排序并没有变化,进行Next等操作时,会出现记录乱跳的情况,应该如下处理:
Prior:
DBView.DataController.FocusedRowIndex := DBView.DataController.FocusedRowIndex - 1;
Next:
DBView.DataController.FocusedRowIndex := DBView.DataController.FocusedRowIndex + 1;
相关文章推荐
- 使用cxGrid对数据集进行Sort和Locate操作
- 在Delphi中使用CreateOleObject方法对WORD文件进行操作
- Delphi中使用RegExpr单元进行匹配与替换操作
- Delphi开发学习二:使用ADOQuery控件对SQL数据库表进行操作
- Delphi中使用RegExpr单元进行匹配与替换操作
- 在Delphi中使用CreateOleObject方法对WORD文件进行操作
- 使用sort命令和awk命令对数据集的label进行处理
- Silverlight 2 (beta1)数据操作(6)——使用LINQ to SQL进行数据CRUD操作(下)
- java并发编程使用锁进行数据同步操作一
- 使用Hibernate进行持久化操作的步骤及示例
- JAVA本地程序使用FileSystemXmlApplicationContext读取application-datasorce.xml进行数据库操作
- 使用 jsoup 对 HTML 文档进行解析和操作
- 【oracle】使用sys进行的操作
- Delphi-XE5-手势操作-Gestures-使用方法
- 使用微软Kinect进行手势识别操作的一个简单范例(2)(WPF-C#)
- 使用delphi+intraweb进行微信开发5—准备实现微信API,先从获取AccessToken开始
- 使用BackgroundWorker组件进行异步操作编程
- 在vs2005里面使用regular expression 进行 find and replace操作
- java使用lambda表达式对List集合进行操作技巧(JDK1.8)
- 【COCOS2DX-LUA 脚本开发之十】使用Lua CJSON库进行encode与decode操作完成对Json数据转化