Ver Mensaje Individual
  #5  
Antiguo 16-08-2012
CSIE CSIE is offline
Miembro
 
Registrado: feb 2008
Ubicación: Universo paralelo
Posts: 69
Reputación: 17
CSIE Va por buen camino
Hola,

En este procedimiento lo que determinas es el tipo de control que TKDBGrid va ha utilizar para editar los datos. Si te fijas en el demo verás:


Código Delphi [-]
procedure TMainForm.DBGridEditorCreate(Sender: TObject; ACol, ARow: Integer;
  var AEditor: TWinControl);
begin
  // you have still full control about the inplace editor but
  // here we just use the default handling
  // (if you delete this event the same is used in TKDBGridCell)
  DBGrid.DefaultEditorCreate(ACol, ARow, AEditor);
  // use default handling for other inplace editor events
end;

Lo que hace aqui es usar el procedimiento por defecto de TKDBGrid, donde asigna el TWinControl a utilizar.


Código Delphi [-]
procedure TKCustomDBGrid.DefaultEditorCreate(ACol, ARow: Integer; var AEditor: TWinControl);
begin
  // create custom editors according to table column type
  if Cols[ACol] is TKDBGridCol then
    case TKDBGridCol(Cols[ACol]).DataType of
      ftString, ftWideString, ftInteger, ftSmallInt, ftWord, ftLargeInt, ftFloat, ftCurrency, ftBcd:
      begin
        AEditor := TEdit.Create(nil);
      end;
      ftMemo
    {$IF DEFINED(FPC) OR DEFINED(COMPILER10_UP)}
      , ftWideMemo
    {$IFEND}
        :
      begin
        AEditor := TMemo.Create(nil);
      end;
      ftDate, ftTime, ftDateTime:
      begin
        AEditor := {$IFDEF FPC}TDateEdit{$ELSE}TDateTimePicker{$ENDIF}.Create(nil);
      end;
      ftBoolean:
      begin
        AEditor := TCheckBox.Create(nil);
      end;
    else
      AEditor := nil;
    end
  else
    AEditor := nil;
end;

Pero utilizando la misma técnica del procedimiento anterior, tu puedes personalizar los controles a utilizar. Por ejemplo si te fijas, cuando el DataType es integer, o string utiliza un TEdit estándard:

Código Delphi [-]
case TKDBGridCol(Cols[ACol]).DataType of
      ftString, ftWideString, ftInteger, ftSmallInt, ftWord, ftLargeInt, ftFloat, ftCurrency, ftBcd:
      begin
        AEditor := TEdit.Create(nil);
      end;

Pero tu podrías mejorarlo usando controles específicos para datos numéricos o de texto o memos.
Responder Con Cita