Ver Mensaje Individual
  #3  
Antiguo 21-07-2011
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola cmfab.
Cita:
lo que necesito es que al hacer click (primario o secundario) el nombre de la columna se convierta en un edit, por ejemplo, donde el usuario va
escribiendo y se va filtrando la informacion que contiene ese campo.
Supongo que te referís al título de la columna. Te pongo un ejemplo que hace lo que buscas.
Código Delphi [-]
...
type
  TDBGrid = class(DBGrids.TDBGrid);
  TForm1 = class(TForm)
    IBDatabase1: TIBDatabase;
    IBTransaction1: TIBTransaction;
    DataSource1: TDataSource;
    IBQuery1: TIBQuery;
    DBGrid1: TDBGrid;
    Edit1: TEdit;
    procedure FormShow(Sender: TObject);
    procedure DBGrid1TitleClick(Column: TColumn);
    procedure Edit1Enter(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
  private
    FFieldName: string;
  public
  end;

var
  Form1: TForm1;

implementation  {$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  Edit1.Visible:= False;
  Edit1.CharCase:= ecUpperCase;
end;

procedure TForm1.DBGrid1TitleClick(Column: TColumn);
var
  R: TRect;
  CT: TColumnTitle;
begin
  FFieldName:= Column.Field.FieldName;
  CT:= TColumnTitle.Create(Column);
  try
    CT.Assign(Column.Title);
    R:= DBGrid1.CellRect(Column.Index+1,0);
    DBGrid1.Canvas.FillRect(R);
    with Edit1 do
    begin
      Left:= R.Left+1;
      Top:= R.Top+1;
      Width:= R.Right - R.Left +1;
      Height:=R.Bottom - R.Top +1;
      Visible:= True;
      SetFocus;
    end;
    Column.Title.Assign(CT);
  finally
    CT.Free;
  end;
end;

procedure TForm1.Edit1Enter(Sender: TObject);
begin
  TEdit(Sender).Text:= '';
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
  if Edit1.Text <> '' then
   with IBQuery1 do
   begin
     Close;
     SQL.Clear;
     SQL.Add('SELECT * FROM TU_TABLA');
     SQL.Add('WHERE UPPER('+FFieldName+') LIKE'+QuotedStr(Edit1.Text+'%'));
     Open;
   end;
end;
end.

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 23-07-2011 a las 01:04:36.
Responder Con Cita