type TcxDataControllerGroupsProtected = class(TcxDataControllerGroups); const MsgDataNotFound = 'Данные, удовлетворяющие условию поиска, не обнаружены'; procedure Search(AView: TcxGridDBBandedTableView; AText: string; AFromBeginning: boolean); var GroupsIndex: integer; GroupsCount: integer; ChildCount: integer; ColIndex: integer; RowIndex: integer; RecIndex: integer; CurIndex: integer; i, j, k: integer; Result: boolean; function Compare(ARecIndex, AColIndex: integer): boolean; begin Result := AnsiContainsText ( AView.DataController.DisplayTexts [ ARecIndex, AView.VisibleColumns[AColIndex].Index ], AText ); end; begin Result := false; if AFromBeginning then begin // поиск с начала // строка - первая // столбец - первый 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 Inc(ColIndex) 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 not Result then raise Exception.Create(MsgDataNotFound); end; |