bonjour,

J'ai 2 questions :

1-
j'ai inséré une combobox dans un TStringGrid selon le code fourni ici :
http://www.developpez.net/forums/showthread.php?t=85126

Voici mon code :
Code c++ : 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
58
59
60
61
62
63
64
65
66
67
 
//---------------------------------------------------------------------------
void __fastcall TfForm::StringGridDrawCell(TObject *Sender, int ACol,
      int ARow, TRect &Rect, TGridDrawState State)
{
    TCanvas *canvasGrid;
    int tW, curCol;
 
    canvasGrid = StringGrid->Canvas;
    curCol = LOWORD((DWORD)ComboBox->Tag);
 
    if (ACol!=0 && ACol!=1 && ARow==0)
    {
        tW = canvasGrid->TextWidth("XXXX") + GetSystemMetrics(SM_CXVSCROLL);
 
        if (StringGrid->ColWidths[ACol]<tW)
            StringGrid->ColWidths[ACol] = tW;
 
        if (StringGrid->ColWidths[ACol]>100)
            StringGrid->ColWidths[ACol] = 100;
    }
 
 
    if (ComboBox->Visible && ACol!=0 && ACol!=1 && ARow==0 && curCol==ACol)
    {
        ComboBox->Left = StringGrid->Left + Rect.Left + StringGrid->GridLineWidth + 1;
        ComboBox->Width = (Rect.Right - Rect.Left);
    }
 
 
}
 
//---------------------------------------------------------------------------
void __fastcall TfForm::StringGridSelectCell(TObject *Sender, int ACol,
      int ARow, bool &CanSelect)
{
    TRect Rect;
    int min, index;
 
 
    Rect = StringGrid->CellRect(ACol, ARow);  //Coordonnées de la cellule cliquée
 
    ComboBox->Visible = false;
 
    ComboBox->Top =  StringGrid->Top + Rect.Top + StringGrid->GridLineWidth + 1;
    ComboBox->Left = StringGrid->Left + Rect.Left + StringGrid->GridLineWidth + 1;
 
    ComboBox->Height = (Rect.Bottom - Rect.Top);
    ComboBox->Width = (Rect.Right - Rect.Left);
 
    min = ComboBox->Canvas->TextWidth("XXXX") + GetSystemMetrics(SM_CXVSCROLL); // largeur de la combo
    if (ComboBox->Width < min)
        ComboBox->Width = min;
 
    index = ComboBox->Items->IndexOf(StringGrid->Cells[ACol][ARow]);
 
    if (index>=0)
        ComboBox->ItemIndex = index;
    else
        ComboBox->ItemIndex = -1;
 
    ComboBox->Tag = MAKELONG (ACol, ARow);
 
    ComboBox->Visible = true;   // Combo visible
    ComboBox->BringToFront();   // 1er plan
 
}

J'arrive à gérer le redimensionnement de la combobox si l'utilisateur redimensionne la cellule, par contre j'ai 2 soucis :
  1. si l'utilisateur fait un scroll, la combo ne se suit pas la colonne dans laquelle il se trouve (scroll.jpg). Dans la copie d'écran fournie en pièce jointe, la combo était dans la cellule 4 avant le scroll.
  2. si l'utilisateur agrandit la colonne au delà de la longueur de la grille, la combo sort de la grille (deborde.jpg)


Comment je peux gérer le scroll et le débordement ?



--------------------------------------
2-
J'avais envisagé une seconde solution en ajoutant dans la fonction StringGridSelectCell cette ligne et modifié le code qui détermine le Heigth, Width, Top et Left de la Combo:
Code c++ : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
    ComboBox->Parent = StringGrid;
cela fonctionne très bien sauf que la Combo ne se déroule plus

Je dois avouer que cette solution me convient danvantage... si je savais comment dérouler la Combo.
Comment je peux dérouler la Combo dans ce cas ?



de vos suggestions