Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   OOP (https://www.clubdelphi.com/foros/forumdisplay.php?f=5)
-   -   Editar memo en DBGrid (https://www.clubdelphi.com/foros/showthread.php?t=57390)

Angel Vicente 13-06-2008 08:03:58

Editar memo en DBGrid
 
Hola a todos...

Estoy haciendo un programa que tiene un DBGrid con campos tipo memo, y me gustaria editarlos, pero dentro de la celda del DBGrid; lo que he encontrado, es la forma de hacerlo, leyendo el contenido del campo y editandolo en un formulario diferente al del DBGrid, para despues sustituir el valor del campo, pero me gustaria hacerlo directamente en la propia celda.

Saludos y gracias de antemano

Caro 13-06-2008 15:19:29

Hola Angel Vicente, para mostrar tu campo memo puedes utilizar el evento OnGetText de tu campo y para editar el evento OnSetText de tu campo. Aquí te pongo el ejemplo:

Código Delphi [-]
procedure TForm1.Table1CampoMemoGetText(Sender: TField; var Text: String;
  DisplayText: Boolean);
begin
 Text := Sender.AsString;
end;

procedure TForm1.Table1CampoMemoSetText(Sender: TField;
  const Text: String);
begin
 Sender.AsString := Text;
end;


Saluditos

Ivanzinho 13-06-2008 15:38:10

Puedes probar de esta manera

Código Delphi [-]
procedure TForm1.dbGrid1EditButtonClick(Sender: TObject);
begin
   //Si el campo seleccionado es el campo blob mostramos el frame
   //con los datos
   if dbGrid1.SelectedField = TablaCampoBlob then
      CrearFrameBlob('CampoBlob', DataSource);
end;

//Crea un frame con un memo donde se puede modificar el campo blob
procedure TForm1.CrearFrameBlob(Campo : string; Source : TDataSource);
const
   ancho = 250;
   alto = 140;
var
   Frm : TForm;
   Memo : TDBMemo;
begin
   Frm := TForm.Create(nil);
   try
      Frm.Width := ancho;
      Frm.Height := alto;
      Frm.Top := Mouse.CursorPos.Y;
      Frm.Left := Mouse.CursorPos.X - ancho;
      if Frm.Left < self.Left then
         Frm.Left := self.Left;
      if Frm.Top + alto > self.Height + self.Top then
         Frm.Top := self.Height + self.Top - alto;
      Frm.BorderStyle := bsToolWindow;
      Frm.Caption := campo;
      Memo := TDBMemo.Create(nil);
      try
         Memo.Parent := Frm;
         Memo.Align := alClient;
         Memo.DataSource := Source;
         Memo.DataField := Campo;
         Memo.ReadOnly := true;
         Memo.ScrollBars := ssVertical;
         Frm.ShowModal;
      finally
         Memo.Free;
      end;
   finally
      Frm.Free;
   end;
end;

//En el dibujado de las celdas creas un rectangulo con el texto del campo
//que se situe sobre la celda requerida
procedure TForm1.dbGrid1DrawColumnCell(Sender: TObject;
  const Rect: TRect; DataCol: Integer; Column: TColumn;
  State: TGridDrawState);
var
   R : TRect;
begin
   R:=Rect;
   Dec(R.Bottom,2);

   if Column.Field = TablaCampoBlob then
      begin
         if not (gdSelected in State) then
            dbgVentas.Canvas.FillRect(Rect);

         DrawText(dbGrid1.Canvas.Handle, pchar(TablaCampoBlob.AsString),
                  length(TablaCampoBlob.AsString), R, DT_WORDBREAK);
      end;
end;

Espero que te sirva.

Un saúdo.


La franja horaria es GMT +2. Ahora son las 13:43:43.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi