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
Dans le Form1.h.
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";
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.
J'ai mis en commentaire l'endroit ou je voudrais faire apparaitre le string, si c'est possible.
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() de la listBox1 } 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 tout essay�, je n'ai jammais r�ussi � faire rentrer un string dans cette listBox.
Je chercherai aussi a remplir un TreeNode.
Merci.
Partager