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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
MultiSelect = false;
pListeIndex = NULL;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
if(pListeIndex != NULL)
delete pListeIndex;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1DrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
TStringGrid *strGrid = (TStringGrid*)Sender;
AnsiString AnsiStr = strGrid->Cells[ACol][ARow];
if (pListeIndex != NULL)
{
if(pListeIndex->IndexOf(ARow) != -1)
{
strGrid->Canvas->Brush->Color = clHighlight; // colorie la ligne pour indiquer qu'elle est selectionnée
strGrid->Canvas->Font->Color = clWhite; // on passe la font de noir à blanche
strGrid->Canvas->FillRect(Rect);
strGrid->Canvas->TextRect(Rect, Rect.Left+2, Rect.Top+2, AnsiStr);
}
else // on est plus en mode multi selection
{ on affiche une font blanche dans la ligne selectionnée et noir pour les autres
if(ARow == strGrid->Row)
strGrid->Canvas->Font->Color = clWhite;
else
strGrid->Canvas->Font->Color = clBlack;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1Click(TObject *Sender)
{
TStringGrid *strGrid = (TStringGrid*)Sender;
if (MultiSelect == true)
{
pListeIndex->Add(strGrid->Row);
}
else
{
if(pListeIndex != NULL)
pListeIndex->Clear();
}
strGrid->Repaint();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1KeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_CONTROL)
{
MultiSelect = true;
if (pListeIndex == NULL)
{
pListeIndex = new TStringList();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1KeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
if (Key == VK_CONTROL)
{
MultiSelect = false;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::StringGrid1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
((TStringGrid*)Sender)->SetFocus();
}
//--------------------------------------------------------------------------- |
Partager