解决方案 »

  1.   

    以下代码仅供参考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;
      

  2.   

    TcxDataControllerGroupsProtected这个是个什么类呢,没找到的
      

  3.   

    另行定义,是为了访问类的保护域成员type
    TcxDataControllerGroupsProtected = class (TcxDataControllerGroups);
      

  4.   

    较麻烦,建议你自己先研究看看,有找到切入点,可再来开帖讨论现在只能说能定位到单元格了,但是显示还是完全不对,表格自带的Search.locate函数可以让单元格高亮显示出来,但是找不到具体这个函数里面是怎么实现的
      

  5.   

    function TcxDataControllerSearch.Locate(AItemIndex: Integer; const ASubText: string): Boolean;
    var
      AFilteredRecordIndex, AStartFilteredRecordIndex, AEndFilteredRecordIndex, AFocusedRecordIndex: Integer;
    begin
      Result := False;
      if (ASubText = '') or (DataController.FilteredRecordCount = 0) then Exit;
      ItemIndex := AItemIndex;
      if DataController.IsGridMode then
        Result := DataController.DoSearchInGridMode(ASubText, True, False)
      else
      begin
        AFocusedRecordIndex := DataController.GetFocusedRecordIndex;
        if AFocusedRecordIndex < 0 then
          AStartFilteredRecordIndex := 0
        else
          AStartFilteredRecordIndex := DataController.FilteredIndexByRecordIndex[AFocusedRecordIndex];
        AFilteredRecordIndex := DoSearch(AStartFilteredRecordIndex, -1, ASubText, True);
        if AFilteredRecordIndex = -1 then
        begin
          AEndFilteredRecordIndex := AStartFilteredRecordIndex - 1;
          AStartFilteredRecordIndex := 0;
          AFilteredRecordIndex := DoSearch(AStartFilteredRecordIndex, AEndFilteredRecordIndex, ASubText, True);
        end;
        if AFilteredRecordIndex <> -1 then
        begin
          DoFocusedRecord(AFilteredRecordIndex);
          Result := True;
        end;
      end;
      if Result then
      begin
        DataController.FIncrementalSearching := True;
        DataController.FIncrementalSearchText := ASubText;
        DataController.Change([dccSearch]);
        DataController.CheckFocusedSelected;
      end;
    end;这个是源码的locate函数,跟进去就不晓得是扎个回事了