Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3424 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [Csharp] - Initialisation d'une combobox (debutant)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[Csharp] - Initialisation d'une combobox (debutant)

n°1422308
BaF - FlOp
Posté le 08-08-2006 à 15:23:57  profilanswer
 

Bonjour,
Je suis un neo-developpeur en C# et j'ai donc des petites questions :)
A commencer par l'initialisation d'une combobox...
 
Apres pas mal de recherche j'ai trouvé la synthaxe suivante (plusieurs sources indiquant cette meme synthaxe)
 

Code :
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace WindowsApplication1
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.             this.cb1.Location = new System.Drawing.Point(8, 312);
  16.             this.cb1.MaxDropDownItems = 15;
  17.             this.cb1.Name = "comboBox1";
  18.             this.cb1.Size = new System.Drawing.Size(232, 24);
  19.             this.cb1.Sorted = true;
  20.             this.cb1.TabIndex = 11;
  21.             this.cb1.Text = "Sélectionnez...";
  22.         }
  23.         public void AddToMyComboBox()
  24.         {
  25.             cb1.BeginUpdate();
  26.             cb1.Items.Add("1" );
  27.             cb1.Text = "";
  28.             cb1.EndUpdate();
  29.         }
  30.     }
  31. }


 
Mais cela ne marche pas [:airforceone]


Message édité par BaF - FlOp le 08-08-2006 à 15:24:32
mood
Publicité
Posté le 08-08-2006 à 15:23:57  profilanswer
 

n°1422311
_Mose_
Lonesome coder
Posté le 08-08-2006 à 15:38:08  profilanswer
 

* Qu'est ce qui ne marche pas ? La compilation ou l'exécution ? Qu'est ce que ça fait ?
* Pourquoi ton champs cbl n'est pas déclaré ?

n°1422317
BaF - FlOp
Posté le 08-08-2006 à 16:01:13  profilanswer
 

Voilà le code en entier :

Code :
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace WindowsApplication1
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.             this.cb1.Location = new System.Drawing.Point(8, 312);
  16.             this.cb1.MaxDropDownItems = 15;
  17.             this.cb1.Name = "cb1";
  18.             this.cb1.Size = new System.Drawing.Size(232, 24);
  19.             this.cb1.Sorted = true;
  20.             this.cb1.TabIndex = 11;
  21.             this.cb1.Text = "Sélectionnez...";
  22.         }
  23.              
  24.         public void AddToMyComboBox()
  25.         {
  26.             cb1.BeginUpdate();
  27.             cb1.Items.Add("1" );
  28.             cb1.Text = "";
  29.             cb1.EndUpdate();
  30.         }
  31.         private void cb1_SelectedIndexChanged(object sender, EventArgs e)
  32.         {
  33.         }
  34.         private void Form1_Load(object sender, EventArgs e)
  35.         {
  36.         }
  37.        }
  38. }


 
Il ne spécifie pas d'erreur, mais n'affiche rien...


Message édité par BaF - FlOp le 08-08-2006 à 16:02:44
n°1422358
_Mose_
Lonesome coder
Posté le 08-08-2006 à 16:57:19  profilanswer
 

Je vais encore passer pour un chieur, mais "ça marche pas", c'est pas un vocabulaire de programmeur, mais un vocabulaire d'utilisateur.
"Ca n'affiche rien", c'est pas beaucoup mieux. "Ca" c'est quoi ? l'application ou la combobox ?
Tu veux dire
a - Que ta combobox apparait mais est vide ?
b - Que ta combobox n'apparait pas ?
 
Pour t'aider dans ton pb :
Dans le code entier il doit y avoir la déclaration de ta ComboBox (private comboBox cbl = null;)
Il doit aussi y avoir une méthode Initializecomponent();
 
Avant de publier l'intégralité (pas forcément nécessaire) vérifie dans cette méthode :
* Que ta combobox est bien ajoutée à la collection de contrôles de ta Form ("this.Controls.Add(this.cbl);" )
* Que la hauteur de ta Form est supérieure à 312 pixel ("this.ClientSize = new Size(xxx, xxx);" )
 

n°1422364
_darkalt3_
Proctopathe
Posté le 08-08-2006 à 17:01:53  profilanswer
 

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [Csharp] - Initialisation d'une combobox (debutant)

 

Sujets relatifs
Quel editeur pour dévelloper en Csharp ?[ Résolu ] Lancer un fichier BAT depuis Csharp
Classement alphanumérique d'une ComboboxQuestion de débutant sur les sessions PHP!
[Access] + [VBA] Deux combobox liées - Au secours[VBA-E] Gestion ComboBox
Débutant, besoin d'aide pour créer site Internet IMPORTANTProblème compliqué pour débutant php
Que signifie ce message d'erreur [débutant]DEVCPP et QT4 => question d un debutant
Plus de sujets relatifs à : [Csharp] - Initialisation d'une combobox (debutant)


Copyright © 1997-2025 Groupe LDLC (Signaler un contenu illicite / Données personnelles)