Ver Mensaje Individual
  #1  
Antiguo 02-09-2016
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Reputación: 19
Angel.Matilla Va por buen camino
Checkbox en un DBGrid

Buenas a todos. A ver si me podéis ayudar que no sé por dónde salir. La aplicaicón está hecah con Builder 6 y tengo este DBGrid cargado a partir de una tabla en FB, por lo tanto no tiene campos tipo BOOL y uso uno SMALLINT, en el que he conseguido meter un Checkbox cogiendo trozos de código.

Y tengo este código:
Código:
void __fastcall TfAboRec::DBGrid1DrawColumnCell(TObject *Sender,
      const TRect &Rect, int DataCol, TColumn *Column,
      TGridDrawState State)
{
     TCanvas *c = DBGrid1->Canvas;
     if (Column->FieldName == "SELECCION")
          DibujarCheckBox(c, Rect, Column->Field->AsInteger);
     else
          DBGrid1->DefaultDrawColumnCell(Rect, DataCol, Column, State);
}
//---------------------------------------------------------------------------

void __fastcall TfAboRec::DibujarCheckBox(TCanvas *c, const TRect &Rect, int Valor)
{
     TRect r = Rect;
     UINT Checked = (!Valor ? DFCS_BUTTONCHECK : DFCS_BUTTONCHECK | DFCS_CHECKED);
     c->FillRect(Rect);
     r.Top += 2;
     r.Bottom -= 1;
     r.Left += 1;
     r.Right -= 1;
     DrawFrameControl(c->Handle, (RECT*)&r, DFC_BUTTON, DFCS_BUTTONCHECK | Checked);
}
//---------------------------------------------------------------------------

void __fastcall TfAboRec::DBGrid1CellClick(TColumn *Column)
{
     int nValor;

     if (Column->FieldName == "SELECCION")
     {
          nValor = Column->Field->AsInteger;

          fPersona->tTemp->Edit();
          fPersona->tTemp->FieldValues[Column->FieldName] = !nValor;
          fPersona->tTemp->Post();
     }
}
//---------------------------------------------------------------------------
Se compila y ejecuta sin ningún problema y el checkbox se marca y desmarca bien, pero a la hora de actualizar el valor de la tabla en función de si está o no marcado el Checkbox no me modificac nada y no sé como arreglarlo.
Responder Con Cita