Suite a ce post
et a ce lien
Voici le code complete pour gerer un CheckBox dans une cellule d'un StringGrid
Sur la Form un StringGrid un CheckBox Visible a false
Le code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
 
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    StringGrid1->Cells[2][0] = "Oui/Non";
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1Click(TObject *Sender)
{
if( StringGrid1->Col == 2 )
{
String d = StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row];
if( d == 0)
{
CheckBox1->State = 0;
}
        else
        {
        CheckBox1->State = 1;
        }
if(d == "")
{
CheckBox1->State = cbUnchecked;
}
        TRect Recto     = StringGrid1->CellRect(StringGrid1->Col, StringGrid1->Row);
        CheckBox1->Top  = StringGrid1->Top;
        CheckBox1->Left = StringGrid1->Left;
        CheckBox1->Top  = CheckBox1->Top + Recto.Top + StringGrid1->GridLineWidth;
        CheckBox1->Left = CheckBox1->Left + Recto.Left + StringGrid1->GridLineWidth + 1;
        CheckBox1->Height = (Recto.Bottom - Recto.Top) + 1;
        CheckBox1->Width  = Recto.Right - Recto.Left;
        CheckBox1->Visible = True;
}
    else
    {
    CheckBox1->Visible = false;
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] = CheckBox1->State;
}
//---------------------------------------------------------------------------