Delphi 在TcxGrid中搜索
我有以下代码可通过DevExpress TcxGrid进行搜索:Delphi 在TcxGrid中搜索,delphi,search,devexpress,tcxgrid,Delphi,Search,Devexpress,Tcxgrid,我有以下代码可通过DevExpress TcxGrid进行搜索: function SearchIncxGrid(AView: TcxGridTableView; AText: string; AFromBeginning: boolean): boolean; function Compare(const ARecIndex, AColIndex: integer): boolean; begin Result := AnsiContainsText(AView.Dat
function SearchIncxGrid(AView: TcxGridTableView; AText: string; AFromBeginning: boolean): boolean;
function Compare(const ARecIndex, AColIndex: integer): boolean;
begin
Result := AnsiContainsText(AView.DataController.DisplayTexts[ARecIndex, AView.VisibleColumns[AColIndex].Index], AText);
end;
var
GroupsIndex: integer;
GroupsCount: integer;
ChildCount: integer;
ColIndex: integer;
RowIndex: integer;
RecIndex: integer;
CurIndex: integer;
i, j, k: integer;
begin
Result := false;
AView.DataController.ClearSelection;
if AFromBeginning then
begin
// поиск с начала
// строка - первая
// столбец - первый
AView.DataController.GotoFirst;
RowIndex := 0;
ColIndex := 0;
end
else
begin
// поиск с текущей позиции
// строка - текущая
// столбец - текущий
// если текущий столбец - последний, то переходим к след. столбцу
RowIndex := AView.Controller.FocusedRowIndex;
ColIndex := AView.Controller.FocusedColumnIndex;
if AView.Controller.FocusedColumn.IsLast then
begin
ColIndex := 0;
Inc(RowIndex);
end
else
begin
Inc(ColIndex)
end;
end;
if AView.DataController.Groups.GroupingItemCount = 0 then
begin
// поиск в несгруппированном представлении
for i := RowIndex to AView.ViewData.RowCount - 1 do
begin
RecIndex := AView.ViewData.Rows[i].RecordIndex;
if RecIndex = -1 then
Continue;
for j := ColIndex to AView.VisibleColumnCount - 1 do
begin
Result := Compare(RecIndex, j);
if Result then
begin
AView.Controller.FocusedRecordIndex := RecIndex;
AView.Controller.FocusedColumnIndex := j;
Break;
end;
end;
ColIndex := 0;
if Result then
Break;
end;
end
else
begin
// поиск в сгруппированном представлении
GroupsCount := TcxDataControllerGroupsProtected(AView.DataController.Groups).DataGroups.Count;
GroupsIndex := AView.DataController.Groups.DataGroupIndexByRowIndex[RowIndex];
for i := GroupsIndex to GroupsCount - 1 do
begin
ChildCount := AView.DataController.Groups.ChildCount[i];
for j := 0 to ChildCount - 1 do
begin
RecIndex := AView.DataController.Groups.ChildRecordIndex[i, j];
if RecIndex = -1 then
Continue;
CurIndex := AView.DataController.GetRowIndexByRecordIndex(RecIndex, false);
if (CurIndex > -1) and (CurIndex < RowIndex) then
Continue;
for k := ColIndex to AView.VisibleColumnCount - 1 do
begin
Result := Compare(RecIndex, k);
if Result then
begin
AView.Controller.FocusedRowIndex := AView.DataController.GetRowIndexByRecordIndex(RecIndex, true);
AView.Controller.FocusedColumnIndex := k;
Break;
end;
end;
ColIndex := 0;
if Result then
Break;
end;
if Result then Break;
end;
end;
// if Result then
// begin
// AView.DataController.ClearSelection;
// AView.Controller.FocusedRecord.Selected := true;
// end;
end;
函数SearchIncxGrid(AView:TcxGridTableView;AText:string;AFromBeginning:boolean):boolean;
函数比较(const ARecIndex,AColIndex:integer):布尔;
开始
结果:=AnsiContainsText(AView.DataController.DisplayTexts[ARecIndex,AView.VisibleColumns[AColIndex].Index],AText);
结束;
变量
GroupsIndex:整数;
groupscont:整数;
ChildCount:整数;
ColIndex:整数;
行索引:整数;
RecIndex:整数;
CurIndex:整数;
i、 j,k:整数;
开始
结果:=假;
AView.DataController.ClearSelection;
如果你是我的话
开始
// поиск с начала
// строка - первая
// столбец - первый
AView.DataController.GotoFirst;
行索引:=0;
ColIndex:=0;
结束
其他的
开始
// поиск с текущей позиции
// строка - текущая
// столбец - текущий
// если текущий столбец - последний, то переходим к след. столбцу
行索引:=AView.Controller.FocusedRowIndex;
ColIndex:=AView.Controller.FocusedColumnIndex;
如果AView.Controller.FocusedColumn.IsLast,则
开始
ColIndex:=0;
公司(指数),;
结束
其他的
开始
公司(ColIndex)
结束;
结束;
如果AView.DataController.Groups.GroupingItemCount=0,则
开始
// поиск в несгруппированном представлении
对于i:=AView.ViewData.RowCount的行索引-1 do
开始
RecIndex:=AView.ViewData.Rows[i].RecordIndex;
如果RecIndex=-1,则
继续;
对于j:=ColIndex to AView.VisibleColumnCount-1 do
开始
结果:=比较(累进指数,j);
如果结果是这样的话
开始
AView.Controller.FocusedRecordIndex:=RecIndex;
AView.Controller.FocusedColumnIndex:=j;
打破
结束;
结束;
ColIndex:=0;
如果结果是这样的话
打破
结束;
结束
其他的
开始
// поиск в сгруппированном представлении
GroupScont:=TcxDataControllerGroupsProtected(AView.DataController.Groups).DataGroups.Count;
GroupsIndex:=AView.DataController.Groups.DataGroupIndexByRowIndex[RowIndex];
对于i:=GroupsIndex to groupscont-1 do
开始
ChildCount:=AView.DataController.Groups.ChildCount[i];
对于j:=0到ChildCount-1 do
开始
RecIndex:=AView.DataController.Groups.ChildRecordIndex[i,j];
如果RecIndex=-1,则
继续;
CurIndex:=AView.DataController.GetRowIndexByRecordIndex(RecIndex,false);
如果(CurIndex>-1)和(CurIndex
只要网格没有排序,搜索就可以正常工作
对cxGrid进行排序时,搜索后光标的位置不正确。
在cxGrid中搜索是否有一个通用且正确的决策?不一定是对您的问题的回答,但可能已经有一种利用代码开发人员Express的方法,您是否可以使用网格提供的增量搜索功能?在帮助文件中,搜索“增量搜索示例”。它向您展示了如何仅用几行代码进行编程。不幸的是,GridView.DataController.Search仅在第一个字符上搜索IncSearch。但是我需要一个POS()搜索。是的,现在我明白为什么需要您自己的搜索代码了。你能描述一下当搜索后光标位置不正确时,你会看到什么样的行为(即光标在哪里结束)?光标会聚焦到另一条记录上。见图