IdentifiantMot de passe
Loading...
Mot de passe oubli� ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les r�ponses en temps r�el, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++Builder Discussion :

ListItem Data Probleme


Sujet :

C++Builder

Vue hybride

Message pr�c�dent Message pr�c�dent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Analyse syst�me
    Inscrit en
    Juin 2012
    Messages
    30
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activit� : Analyse syst�me
    Secteur : Administration - Collectivit� locale

    Informations forums :
    Inscription : Juin 2012
    Messages : 30
    Par d�faut ListItem Data Probleme
    Bonjours,
    j'ai un gros probleme avec une appli, voici 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
     
    //Unit1.cpp
    //---------------------------------------------------------------------------
    #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::Button1Click(TObject *Sender)
    {
            info n1;
     
            n1.nom = Edit1->Text;
            n1.age = StrToInt(Edit2->Text);
            n1.metier = Edit3->Text;
     
            ShowMessage(IntToStr(n1.age));
     
            TListItem *LI;
     
            LI = ListView1->Items->Add();
     
            LI->Caption = ListView1->Items->Count;
            LI->Data = &n1;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button2Click(TObject *Sender)
    {
            for(int i(0); i<ListView1->Items->Count; i++)
            {
                    TListItem *LI;
                    info *n2;
     
                    LI = ListView1->Items->Item[i];
                    n2 = (info *)LI->Data;
     
                    LI->SubItems->Add(n2->nom);
                    LI->SubItems->Add(n2->age);
                    LI->SubItems->Add(n2->metier);
            }
    }
    //---------------------------------------------------------------------------
    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
     
    //Unit1.h
    //---------------------------------------------------------------------------
     
    #ifndef Unit1H
    #define Unit1H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ComCtrls.hpp>
    //---------------------------------------------------------------------------
    struct info
    {
            public:
            String nom;
            int age;
            String metier;
    };
    //---------------------------------------------------------------------------
    class TForm1 : public TForm
    {
    __published:	// IDE-managed Components
            TListView *ListView1;
            TEdit *Edit1;
            TEdit *Edit2;
            TEdit *Edit3;
            TLabel *Label1;
            TLabel *Label2;
            TLabel *Label3;
            TButton *Button1;
            TButton *Button2;
            void __fastcall Button1Click(TObject *Sender);
            void __fastcall Button2Click(TObject *Sender);
    private:	// User declarations
    public:		// User declarations
            __fastcall TForm1(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm1 *Form1;
    //---------------------------------------------------------------------------
    #endif
    Mais voila quand je clique sur le bouton 2 rien ne se passe :/

    Merci d'avance ^^

  2. #2
    Membre Expert
    Avatar de DjmSoftware
    Homme Profil pro
    Responsable de compte
    Inscrit en
    Mars 2002
    Messages
    1 044
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activit� : Responsable de compte
    Secteur : High Tech - Op�rateur de t�l�communications

    Informations forums :
    Inscription : Mars 2002
    Messages : 1 044
    Billets dans le blog
    1
    Par d�faut
    Salut
    Plusieurs Petites fautes

    1. tu dois cr�er dynamiquement un object de type info et non pas de mani�re statique
    2. la propri�t� ViewStyle doit �tre position�e sur VSReport
    3. tu dois avoir autant de colonnes que Caption + le nombre de subItems (4 dans ton exemple)

    ton code revu
    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
    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
     
    //---------------------------------------------------------------------------
     
    #ifndef Unit7H
    #define Unit7H
    //---------------------------------------------------------------------------
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <Forms.hpp>
    #include <ComCtrls.hpp>
    //---------------------------------------------------------------------------
     
    struct minfo
    {
    	 AnsiString  nom;
    	 int age;
    	 AnsiString metier;
    };
     
     
     
     
    class TForm7 : public TForm
    {
    __published:	// Composants gérés par l'EDI
    	TListView *ListView1;
    	TEdit *Edit1;
    	TEdit *Edit2;
    	TEdit *Edit3;
    	TLabel *Label1;
    	TLabel *Label2;
    	TLabel *Label3;
    	TButton *Button3;
    	TButton *Button4;
    	void __fastcall Button3Click(TObject *Sender);
    	void __fastcall Button4Click(TObject *Sender);
    	void __fastcall FormDestroy(TObject *Sender);
    private:	// Déclarations utilisateur
    public:		// Déclarations utilisateur
    	__fastcall TForm7(TComponent* Owner);
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm7 *Form7;
    //---------------------------------------------------------------------------
    #endif
    // le cpp
    // ---------------------------------------------------------------------------
     
    #include <vcl.h>
    #pragma hdrstop
     
    #include "Unit7.h"
    // ---------------------------------------------------------------------------
    #pragma package(smart_init)
    #pragma resource "*.dfm"
    TForm7 *Form7;
     
    // ---------------------------------------------------------------------------
    __fastcall TForm7::TForm7(TComponent* Owner) : TForm(Owner) {
     
    	ListView1->ViewStyle = vsReport;
    	ListView1->Items->BeginUpdate();
    	for (int col(0); col < 4; col++)
    		ListView1->Columns->Add();
    	ListView1->Items->EndUpdate();
    }
     
    // ---------------------------------------------------------------------------
    void __fastcall TForm7::Button3Click(TObject *Sender) {
    	minfo* n1 = new minfo(); // new record
    	// n1->nom = new char(Edit1->Text.Length()); // reservation Memoire Buffer
    	n1->nom = Edit1->Text;
    	n1->age = StrToInt(Edit2->Text);
    	n1->metier = Edit3->Text;
    	TListItem *LI;
    	LI = ListView1->Items->Add();
    	LI->Caption = ListView1->Items->Count;
    	LI->Data = n1;
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm7::Button4Click(TObject *Sender) {
    	TListItem *LI;
    	minfo *n2;
    	ListView1->Items->BeginUpdate();
    	for (int i(0); i < ListView1->Items->Count; i++) {
    		LI = ListView1->Items->Item[i];
    		if (LI->SubItems->Count)
    			LI->SubItems->Clear(); // on efface la liste précédente si existante
    		n2 = (minfo*)LI->Data;
    		LI->SubItems->Add(n2->nom);
    		LI->SubItems->Add(n2->age);
    		LI->SubItems->Add(n2->metier);
    	}
    	ListView1->Items->EndUpdate();
    }
    // ---------------------------------------------------------------------------
     
    void __fastcall TForm7::FormDestroy(TObject *Sender) {
    	TListItem *LI;
    	minfo *n2;
    	ListView1->Items->BeginUpdate();
    	for (int i(0); i < ListView1->Items->Count; i++) {
    		LI = ListView1->Items->Item[i];
    		n2 = (minfo*)LI->Data;
    		delete n2; // on libère les buffer
    	}
    	ListView1->Items->EndUpdate();
    }
    // ---------------------------------------------------------------------------
    cdlt
    vous trouverez mes tutoriels � l'adresse suivante: http://djmsoftware.developpez.com/
    je vous en souhaite une excellente lecture ...

    A lire : Les r�gles du forum

  3. #3
    Membre actif
    Homme Profil pro
    Analyse syst�me
    Inscrit en
    Juin 2012
    Messages
    30
    D�tails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activit� : Analyse syst�me
    Secteur : Administration - Collectivit� locale

    Informations forums :
    Inscription : Juin 2012
    Messages : 30
    Par d�faut
    Merci beaucoup sa a r�solue mon probleme

+ R�pondre � la discussion
Cette discussion est r�solue.

Discussions similaires

  1. [XCode] Core Data problem
    Par shadow578 dans le forum Objective-C
    R�ponses: 1
    Dernier message: 19/03/2013, 12h24
  2. Python base64 decode data | Probleme
    Par Maxou56800 dans le forum G�n�ral Python
    R�ponses: 6
    Dernier message: 27/12/2011, 17h03
  3. [EF] [Dynamic Data] Probleme format date
    Par lvedrines dans le forum ASP.NET
    R�ponses: 2
    Dernier message: 27/04/2011, 18h43
  4. R�ponses: 1
    Dernier message: 20/08/2009, 12h12
  5. probleme avec "LOAD DATA INFILE" et les b
    Par Koo dans le forum Requ�tes
    R�ponses: 2
    Dernier message: 01/07/2004, 09h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo