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

Visual C++ Discussion :

Visual C++ Express 2010. Les Chaines de caractéres. Que faut il utiliser ?


Sujet :

Visual C++

  1. #1
    Membre du Club Avatar de Gilles57-H-G
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 88
    Points : 62
    Points
    62
    Par défaut Visual C++ Express 2010. Les Chaines de caractéres. Que faut il utiliser ?
    La classe CString de Microsoft n'étant pas présente sur la version Express de Visual C++.

    Je me suis tourné vers la classe string.
    J'ai fait
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    #include <string>
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    #include "stdlib.h"
    #include <stdio.h>
    #include <sstream>
     
     
    using namespace std;
     
    string chaine;
     
    chaine = "Apparition";
    Dans le Form1.h.
    Fonctionne, ne crée pas d'erreur.


    Je voudrais remplir une ListBox.

    L'exemple de code suivant illustre la création d'un contrôle ListBox qui affiche plusieurs éléments.
    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
     string chaine;
    chaine = "Apparition";
     
     // Create an instance of the ListBox.
       ListBox^ listBox1 = gcnew ListBox;
     
       // Set the size and location of the ListBox.
       listBox1->Size = System::Drawing::Size( 200, 100 );
       listBox1->Location = System::Drawing::Point( 10, 10 );
     
       // Add the ListBox to the form.
       this->Controls->Add( listBox1 );
     
       // Set the ListBox to display items in multiple columns.
       listBox1->MultiColumn = true;
     
       // Set the selection mode to multiple and extended.
       listBox1->SelectionMode = SelectionMode::MultiExtended;
     
       // Shutdown the painting of the ListBox as items are added.
       listBox1->BeginUpdate();
     
       // Loop through and add 50 items to the ListBox.
       for ( int x = 1; x <= 50; x++ )
       {
     
    ///////////////////////////////////////
     
    listBox1->Items->Add( String::Format( "Item {0}", x ) );
     
     
       //  Je voudrais faire apparaitre chaine qui est de type string
               //                  dans la fonction Add()
     
                                                                          }
       listBox1->EndUpdate();
     
       // Select three items from the ListBox.
       listBox1->SetSelected( 1, true );
       listBox1->SetSelected( 3, true );
       listBox1->SetSelected( 5, true );
     
       // Display the second selected item in the ListBox to the console.
       System::Diagnostics::Debug::WriteLine( listBox1->SelectedItems[ 1 ] );
     
       // Display the index of the first selected item in the ListBox.
       System::Diagnostics::Debug::WriteLine( listBox1->SelectedIndices[ 0 ] );
    J'ai mis en commentaire l'endroit ou je voudrais faire apparaitre mon string, si c'est possible.

    J'ai tout essayé, je n'ai jammais réussi à faire rentrer un string dans cette listBox.


    Je chercherai aussi a remplir un TreeNode

    Merci.

  2. #2
    Membre éclairé

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    426
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations forums :
    Inscription : Octobre 2008
    Messages : 426
    Points : 827
    Points
    827
    Par défaut
    Puisque tu utilise des Forms, tu devrais plutôt utiliser la classe : String avec un "S" majuscule : http://msdn.microsoft.com/fr-fr/libr...em.string.aspx

    Et ton code deviens :
    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
    String^ chaine;
    chaine = "Apparition";
     
     // Create an instance of the ListBox.
       ListBox^ listBox1 = gcnew ListBox;
     
       // Set the size and location of the ListBox.
       listBox1->Size = System::Drawing::Size( 200, 100 );
       listBox1->Location = System::Drawing::Point( 10, 10 );
     
       // Add the ListBox to the form.
       this->Controls->Add( listBox1 );
     
       // Set the ListBox to display items in multiple columns.
       listBox1->MultiColumn = true;
     
       // Set the selection mode to multiple and extended.
       listBox1->SelectionMode = SelectionMode::MultiExtended;
     
       // Shutdown the painting of the ListBox as items are added.
       listBox1->BeginUpdate();
     
       // Loop through and add 50 items to the ListBox.
       for ( int x = 1; x <= 50; x++ )
       {
     
    ///////////////////////////////////////
     
    listBox1->Items->Add( chaine );
     
     
       //  Je voudrais faire apparaitre chaine qui est de type string
               //                  dans la fonction Add()
     
                                                                          }
       listBox1->EndUpdate();
     
       // Select three items from the ListBox.
       listBox1->SetSelected( 1, true );
       listBox1->SetSelected( 3, true );
       listBox1->SetSelected( 5, true );
     
       // Display the second selected item in the ListBox to the console.
       System::Diagnostics::Debug::WriteLine( listBox1->SelectedItems[ 1 ] );
     
       // Display the index of the first selected item in the ListBox.
       System::Diagnostics::Debug::WriteLine( listBox1->SelectedIndices[ 0 ] );
    J'espère que ça marche!
    Bertrand

  3. #3
    Membre du Club Avatar de Gilles57-H-G
    Profil pro
    Inscrit en
    Novembre 2010
    Messages
    88
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2010
    Messages : 88
    Points : 62
    Points
    62
    Par défaut
    Super cela fonctionne.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 6
    Dernier message: 08/12/2010, 19h03
  2. Réponses: 8
    Dernier message: 03/12/2010, 01h32
  3. question sur les chaines de caractères
    Par pierrOPSG dans le forum C
    Réponses: 5
    Dernier message: 13/04/2006, 18h55
  4. les chaines de caractères
    Par mrtatou dans le forum C
    Réponses: 4
    Dernier message: 25/01/2006, 14h18
  5. xsl : test sur les chaine de caractère
    Par yos dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 13/07/2005, 15h43

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