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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
   |  #//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "Unit5.h"
#include "StrGrid.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
  : TForm(Owner)
{   i=2;
    StringGrid1->Cells[0][0] = "N° VM";          //sert à afficher dans la case [0][0] de l'entête
    StringGrid1->Cells[1][0] = "Nom du projet";  //sert à afficher dans la case [1][0] de l'entête
    StringGrid1->Cells[2][0] = "Adresse IP";
    StringGrid1->Cells[3][0] = "Port";
    StringGrid1->FixedCols = 1 ;                //met en grisé la 1ere colonne
    StringGrid1->ColCount=4;                    //Ici, notre tableau sera composé de 4 colones
    StringGrid1->RowCount=2;                    //Ici, notre tableau sera composé de 2 lignes
    StringGrid1->Height=55;                     //permet de redéfinir note interface pour notre tableau pour la hauteur
    StringGrid1->Width=408;                     //permet de redéfinir note interface pour notre tableau pour la largeur
    StringGrid1->Cells[0][1] = "VM1";           //permet d'écrire "Vm1" dans la case[0][1]
 
}
//---------------------------------------------------------------------------
void __fastcall TForm2::DBGrid1KeyPress(TObject *Sender, char &Key)
{
 
}
//---------------------------------------------------------------------------
 
void __fastcall TForm2::LabeledEdit1Change(TObject *Sender)
{
 
}
//---------------------------------------------------------------------------
void __fastcall TForm2::AjouterClick(TObject *Sender)   //permet d'ajouter une ligne si l'utilisateur appuie sur le bouton '+'
{                                                       //s'il veut rajouter une VM
    StringGrid1->Cells[0][i] ="VM"+String(i);          //permet d'afficher les VM i à chaque fois qu'on appuie sur '+'
   i++;
   StringGrid1->RowCount++;                           //rajoute une ligne
   StringGrid1->Height=(StringGrid1->Height+25);      //permet d'afficher les bonnes dimensions de l'interface
   StringGrid1->Width;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::RetirerClick(TObject *Sender)
{
 
 try
{
  //...
   if(StringGrid1->RowCount==2)                         // si il ne reste que 2 lignes on affiche un message d'erreur
    {
        //ShowMessage(AnsiString("Attention, vous ne pouvez pas supprimer cette ligne"));
        MessageBox(0,"Attention, vous ne pouvez pas supprimer cette ligne.\n", "Attention", MB_OK);
    }
  else
  {
    StringGrid1->RowCount--;                           //sinon on efface les lignes
    StringGrid1->Height=(StringGrid1->Height-25);
  }
}
catch(Exception &e)
{
      ShowMessage("Erreur");
}
 
}
//---------------------------------------------------------------------------
 
void __fastcall TForm2::StringGrid1SetEditText(TObject *Sender, int ACol,
      int ARow, const AnsiString Value)
{
    StringGrid1->OnDblClick;
    Edit1->Text = Value;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::StringGrid1DblClick(TObject *Sender)   //permet d'écrire dans le tableau après avoir double cliquer dans une case
{
     if(StringGrid1->Col==1)         //si on double-clique dans la 1ère colonne
     {  Form3->Show();               //On ouvre le formulaire correspondant
        goEditing==false;            //on interdit d'écrire dans le tableau
     }
     else if(StringGrid1->Col==2)    //si on double-clique dans la 2ème colonne
     {  Form4->Show();               //On ouvre le formulaire correspondant
        goEditing==false;            //on interdit d'écrire dans le tableau
     }
     else
     {                               //sinon si on double-clique dans la dernière colonne
       Form5->Show();                //On ouvre le formulaire correspondant
       goEditing==false;             //on interdit d'écrire dans le tableau
     }
 
}
//---------------------------------------------------------------------------
 
void __fastcall TForm2::EffacerClick(TObject *Sender)
{
     TStrGrid * MyStrGrid = (TStrGrid *)StringGrid1;
 
    MyStrGrid->DeleteRow(5);        // Supprime la ligne 6
  //  StringGrid1->DeleteCol(7);        // Supprime la colonne 8
   // StringGrid1->MoveRow(2, 10);      // Déplace la ligne 3 à la ligne 11
   // StringGrid1->MoveColumn(8, 1);    // Déplace la colonne 9 à la colonne
 
}
//---------------------------------------------------------------------------
# | 
Partager