Angel Master


Registrado: 15 Abr 2003Mensajes: 2311Ubicación: Toledo (España)
|
Publicado: Vie 02 Sep, 2016 10:07 am Asunto: Checkbox en un DBGrid |
|
|
Buenas a todos. A ver si me podéis ayudar que no sé por dónde salir. 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 de este y otros foros.
La tabla está definida así:
| Código: | CREATE TABLE Tabla (Identidad VARCHAR(60), Referencia VARCHAR(13), Codigo INTEGER, Importe DECIMAL(9,2), Seleccion SMALLINT DEFAULT 0, PRIMARY KEY (Identidad, Referencia, Codigo)) |
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. _________________ Un saludo
Necesitamos tu ayuda: Envía AI al 27595 (Coste 1,20 euros + IVA) |
|