Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   LookupDataset en DBGrid y DrawColumnCell (https://www.clubdelphi.com/foros/showthread.php?t=92896)

wilcg 06-03-2018 19:03:32

LookupDataset en DBGrid y DrawColumnCell
 
Buen día,
Quisiera que me ayudaran con este codigo.
Tengo un DBGrid con los campos ID_CONFIG, ID_SUCURSAL. en este ultimo quiero mostrar el nombre de la sucursal mediante un LookupDataset, realizo la configuracion
y enlazo a un Query que contiene la informacion ID_SUCURSAL y NOMBRE. El programa funciona bien. Lo que sucede es que quiero usar este codigo que se muestra abajo,
en el evento DrawColumnCell y no me trae el nombre de la sucursal correctamente, me toma el primer nombre para todos los registros.

Código Delphi [-]
const
  // Windwos classic
  CtrlState: Array[Boolean] of Integer = (DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or
  DFCS_CHECKED);
  // Windows xp
  CtrlStateXP: Array [Boolean] of TThemedButton = (tbCheckBoxUncheckedNormal,
  tbCheckBoxCheckedNormal);
var
  R      : TRect;
  uFormat: LongWord;
  currFld: string;
  Details: TThemedElementDetails;
begin
  uFormat := DT_SINGLELINE or DT_VCENTER or DT_END_ELLIPSIS;
  case Column.Alignment of
    taLeftJustify : uFormat := uFormat or DT_LEFT;
    taRightJustify: uFormat := uFormat or DT_RIGHT;
    taCenter      : uFormat := uFormat or DT_CENTER;
  end;

  with TDBGridEh(Sender) do
  begin
    if gdSelected in State then
    begin
      Canvas.Brush.Color := $00BC7D00;
      Canvas.Font.Color := clWhite;
      Canvas.Font.Name := 'Tahoma';
      Canvas.Font.Size := 9;
    end
      else
    begin
      Canvas.Font.Color := $00646464;
      Canvas.Font.Name := 'Tahoma';
      Canvas.Font.Size := 8;
    end;

    currFld := column.Field.AsString;

    if column.FieldName = 'id_config' then
      if Length(Trim(column.Field.AsString)) > 0 then
        currFld := FormatFloat('000000',column.Field.Value);
    if column.FieldName = 'id_sucursal' then
      if Length(Trim(column.Field.AsString)) > 0 then
          currFld := ' '+column.Field.LookupDataSet.FieldByName('nombre').AsString;

    R := Rect;
    Canvas.FillRect(R);
    DrawText(Canvas.Handle, PChar(currFld), -1, R, uFormat);

    if Column.Field.DataType = ftBoolean then
    begin
      Canvas.FillRect(Rect);
      if ThemeServices.ThemesEnabled then
      begin
        Details := ThemeServices.GetElementDetails(CtrlStateXP[Column.Field.AsBoolean]);
        ThemeServices.DrawElement(Canvas.Handle, Details, Rect);
      end else
      begin
        R.Left   := Rect.Left + 2;
        R.Right  := Rect.Right - 2;
        R.Top    := Rect.Top + 2;
        R.Bottom := Rect.Bottom - 2;
        DrawFrameControl(Canvas.Handle, R, DFC_BUTTON, CtrlState[Column.Field.AsBoolean]);
      end;
    end;
  end;

que es lo que falta para que funcione correctamente.

Casimiro Notevi 06-03-2018 20:13:56

¿Por qué no traes el nombre en el select del dataset?

wilcg 07-03-2018 04:58:48

lo que sucede es que al usar el código no trae el campo solicitado mediante el LookupDataset solo muestra el dato del campo enlazado mas no el campo que se esperaría mediante la conexión Lookup.

Casimiro Notevi 07-03-2018 10:47:18

Bien, y ese lookupdataset ¿qué parámetros tiene?


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

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