Suite a ce post
et a ce lien
Voici le code complete pour gerer un ListBox dans une cellule d'un StringGrid
Sur la Form un StringGrid un ListBox les Items completes et 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 //--------------------------------------------------------------------------- #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[4][0] = "Nom"; } //--------------------------------------------------------------------------- void __fastcall TForm1::StringGrid1Click(TObject *Sender) { if( StringGrid1->Col == 4 ) { String d = StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row]; for(int a = 0; a < ListBox1->Items->Count; a++) { if(d == ListBox1->Items->Strings[a]) { ListBox1->ItemIndex = a; StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] = ListBox1->Items->Strings[a]; } } TRect Recto = StringGrid1->CellRect(StringGrid1->Col, StringGrid1->Row); ListBox1->Top = StringGrid1->Top; ListBox1->Left = StringGrid1->Left; ListBox1->Top = ListBox1->Top + Recto.Top + StringGrid1->GridLineWidth; ListBox1->Left = ListBox1->Left + Recto.Left + StringGrid1->GridLineWidth + 1; ListBox1->Height = (Recto.Bottom - Recto.Top) + 1; ListBox1->Width = Recto.Right - Recto.Left; ListBox1->Visible = True; ListBox1->BringToFront(); } else { ListBox1->Visible = false; } } //--------------------------------------------------------------------------- void __fastcall TForm1::ListBox1Click(TObject *Sender) { StringGrid1->Cells[StringGrid1->Col][StringGrid1->Row] = ListBox1->Items->Strings[ListBox1->ItemIndex]; } //---------------------------------------------------------------------------
Partager