CXGRID,定位并高亮

var
  I, FoundPos: integer;
  AColumn : TcxGridDBColumn;
  AText : String;
begin
  AText := 'Blue Sports';
  with cxGrid1DBTableView1 do
  begin
    AColumn := GetColumnByFieldName('Company');
    for I := 0 to ViewData.RecordCount - 1 do
      if ViewData.Rows[I].IsData then
      begin
        ViewData.Rows[I].Focused := True;
        with Controller.EditingController do
        begin
          ShowEdit(AColumn);
          FoundPos := TcxRichEdit(Edit).FindText(AText, 0, Length(TcxRichEdit(Edit).Text), [stMatchCase]);
          if not (FoundPos < 0) then
          begin
            TcxRichEdit(Edit).SelStart := FoundPos;
            TcxRichEdit(Edit).SelLength := Length( AText);
            SendMessage(TcxRichEdit(Edit).InnerControl.Handle,EM_SCROLLCARET, 0, 0);
            Break;
          end
          else
            AColumn.Editing := False;
        end;
      end;
   end;
end;

 

直接摘的代码,原文出处:

http://www.devexpress.com/Support/Center/p/B3656.aspx?searchtext=Allow

你可能感兴趣的:(grid)