Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   FireMonkey (https://www.clubdelphi.com/foros/forumdisplay.php?f=50)
-   -   pintar linea en grid segun condicion (https://www.clubdelphi.com/foros/showthread.php?t=96148)

giantonti1801 08-03-2023 14:56:04

pintar linea en grid segun condicion
 
amigo tengo 2 dias dandole vuenta a como pintar una linea dentro del stringrid segun su condicion pero aun no lo logro.
mi stringrid se alimenta de una base de dato y lo que quiero lograr ejemplo: Si el valor del campo es igual a 'Pendiente' entonces que me pinte la linea, me cambie el color de la fuente y me coloque el fuente en negrita pero a pezar de mi consulta e investigaciones aun no lo logro. le envio codigo con lo que lo estoy intentando hacer en este momento pero nada que funciona.
Código Delphi [-]
procedure TForm1.StringGrid1DrawColumnBackground(Sender: TObject;
  const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
  const Row: Integer; const Value: TValue; const State: TGridDrawStates);
begin
with stringGrid1 do
//  with canvas do
       //begin
       if UniQueryFICPACESTATUSCONSULTA.AsString = 'PENDIENTE' then
       //if ADOQuery1EST.value = 'DIRIJASE A CAJA'  then
       //else if ADOQuery1EST.value = 'Atendiendo' then
       begin
       stringGrid1.TextSettings.FontColor := clGray;
       stringGrid1.TextSettings.Font.Size  := 18;
       //TFontStyle.fsBold
       //stringGrid1.TextSettings.Font.Style.  :=  TFontStyle.fsBold;
       //stringGrid1.TextSettings.Font.Style.  :=  TFontStyle.fsBold;
       //stringGrid1.DefaultDrawing.(Fill) .Color := clWebGreenYellow;
       //stringGrid1.DefaultDrawColumnCell(rect,datacol, column, State);
       end;

  end;

chenech 08-03-2023 15:44:00

Esto en en VCL, no se si en FMX será igual. Yo lo tengo pero en C++ Builder y lo hago en DrawColumnCell, si alguien lo puede convertir a Delphi:
Si es NOMCLI un color, si es PRT otro, etc,, y si es la seleccionada rojo y negrita, y para la columna 0 otro color, espero te sirva.

Código:

void __fastcall TForm416::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect,
                                        int DataCol, TColumn *Column, TGridDrawState State)
{
        TDataSet *dataset = Column->Field->DataSet;
        if(dataset->FieldByName("NOMCLI")->AsString.Length() < 1)
          DBGrid1->Canvas->Brush->Color = clCream;
        else
        {
          if(dataset->FieldByName("NOMHAB")->AsString == "¡¡¡ BLOQUEADA !!!")
                DBGrid1->Canvas->Brush->Color = clSilver;
          else
                DBGrid1->Canvas->Brush->Color = clSkyBlue;
        }
        if(dataset->FieldByName("TIPOHAB")->AsString.SubString(1, 3) == "PRT")
                DBGrid1->Canvas->Brush->Color = clOlive;

// Para lo seleccionado cambio el color a rojo y negrita

        if(State.Contains(Grids::gdSelected))
        {
                DBGrid1->Canvas->Font->Color = clRed;
                DBGrid1->Canvas->Font->Style = TFontStyles() << fsBold;
        }
        DBGrid1->DefaultDrawColumnCell(Rect, DataCol, Column, State);

// Aqui cambio solo la primera columna si es S o P

        if(DataCol == 0)
        {
          if(dataset->FieldByName("LIMPIA")->AsString == "S")
                DBGrid1->Canvas->Brush->Color = clGreen;
          else
          {
                if(dataset->FieldByName("LIMPIA")->AsString == "P")
                        DBGrid1->Canvas->Brush->Color = clYellow;
                else
                        DBGrid1->Canvas->Brush->Color = clRed;
          }
          DBGrid1->DefaultDrawDataCell(Rect, Column->Field, State);
  }
}
//---------------------------------------------------------------------------


giantonti1801 09-03-2023 01:10:26

Cita:

Empezado por chenech (Mensaje 550685)
Esto en en VCL, no se si en FMX será igual. Yo lo tengo pero en C++ Builder y lo hago en DrawColumnCell, si alguien lo puede convertir a Delphi:
Si es NOMCLI un color, si es PRT otro, etc,, y si es la seleccionada rojo y negrita, y para la columna 0 otro color, espero te sirva.

Código:

void __fastcall TForm416::DBGrid1DrawColumnCell(TObject *Sender, const TRect &Rect,
                                        int DataCol, TColumn *Column, TGridDrawState State)
{
        TDataSet *dataset = Column->Field->DataSet;
        if(dataset->FieldByName("NOMCLI")->AsString.Length() < 1)
          DBGrid1->Canvas->Brush->Color = clCream;
        else
        {
          if(dataset->FieldByName("NOMHAB")->AsString == "¡¡¡ BLOQUEADA !!!")
                DBGrid1->Canvas->Brush->Color = clSilver;
          else
                DBGrid1->Canvas->Brush->Color = clSkyBlue;
        }
        if(dataset->FieldByName("TIPOHAB")->AsString.SubString(1, 3) == "PRT")
                DBGrid1->Canvas->Brush->Color = clOlive;

// Para lo seleccionado cambio el color a rojo y negrita

        if(State.Contains(Grids::gdSelected))
        {
                DBGrid1->Canvas->Font->Color = clRed;
                DBGrid1->Canvas->Font->Style = TFontStyles() << fsBold;
        }
        DBGrid1->DefaultDrawColumnCell(Rect, DataCol, Column, State);

// Aqui cambio solo la primera columna si es S o P

        if(DataCol == 0)
        {
          if(dataset->FieldByName("LIMPIA")->AsString == "S")
                DBGrid1->Canvas->Brush->Color = clGreen;
          else
          {
                if(dataset->FieldByName("LIMPIA")->AsString == "P")
                        DBGrid1->Canvas->Brush->Color = clYellow;
                else
                        DBGrid1->Canvas->Brush->Color = clRed;
          }
          DBGrid1->DefaultDrawDataCell(Rect, Column->Field, State);
  }
}
//---------------------------------------------------------------------------


gracias por tu respuesta, pero en DBgrid no tengo problema eso se hace de forma facil pero el problema lo tengo en el stringrid que no consigo ni forma ni manera de hacerlo.

chenech 09-03-2023 13:49:07

Esto lo acabo de probar en FMX con StringGrid y me funciona en StringGrid1DrawColumnCell
Sacado de aqi:
https://stackoverflow.com/questions/...grid-row-color

Código:

var
  aRowColor: TBrush;
  aNewRectF: TRectF;
begin
  aRowColor := TBrush.Create(TBrushKind.Solid, TAlphaColors.Alpha);

  if (StringGrid1.Cells[7, Row] = '1') then
    aRowColor.Color := TAlphaColors.Green
  else
    aRowColor.Color := TAlphaColors.Red;
  aNewRectF := Bounds;
  aNewRectF.Inflate(3, 3);
  Canvas.FillRect(aNewRectF, 0, 0, [], 1, aRowColor);
  Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
  aRowColor.free;


pgranados 09-03-2023 20:11:53

Con un componente de 1st Class lo logro en el evento OnDrawDataCell

Código Delphi [-]
procedure TFormaAdministrarXML.wwDBGrid1DrawDataCell(Sender: TObject;
  const Rect: TRect; Field: TField; State: TGridDrawState);
begin
      if DModuloEmpresa.FDQueryUsuarios.FieldByName('USUARIO').Value <> '' then
        wwDBGrid1.Canvas.Brush.Color:= wwDBGrid1.Color
      else
        wwDBGrid1.Canvas.Brush.Color:= clRed; // Vacio

      wwDBGrid1.DefaultDrawDataCell(rect, field, state);
end;

giantonti1801 10-03-2023 01:58:44

Cita:

Empezado por chenech (Mensaje 550696)
Esto lo acabo de probar en FMX con StringGrid y me funciona en StringGrid1DrawColumnCell
Sacado de aqi:
https://stackoverflow.com/questions/...grid-row-color

Código:

var
  aRowColor: TBrush;
  aNewRectF: TRectF;
begin
  aRowColor := TBrush.Create(TBrushKind.Solid, TAlphaColors.Alpha);

  if (StringGrid1.Cells[7, Row] = '1') then
    aRowColor.Color := TAlphaColors.Green
  else
    aRowColor.Color := TAlphaColors.Red;
  aNewRectF := Bounds;
  aNewRectF.Inflate(3, 3);
  Canvas.FillRect(aNewRectF, 0, 0, [], 1, aRowColor);
  Column.DefaultDrawCell(Canvas, Bounds, Row, Value, State);
  aRowColor.free;


gracias amigo Funciona perfecto pero ahora estoy buscando de cambiar el color de la fuente y colocarlo en negrita en la misma celda seleccionada en verde y no se como hacerlo


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

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