Tableau simple en C#

Résolu
SinXJon Messages postés 4 Date d'inscription mardi 5 décembre 2006 Statut Membre Dernière intervention 13 février 2007 - 12 févr. 2007 à 00:03
SinXJon Messages postés 4 Date d'inscription mardi 5 décembre 2006 Statut Membre Dernière intervention 13 février 2007 - 13 févr. 2007 à 04:48
Bonjour a tous!



J'essaie de me créer 2 tableau que je pourrai ensuite afficher dans 2 textbox nommer txtDescription et txtPrix.
je veux que lorsque que je choisit un # d'item dans un combobox (1 a 5) que l information des tableau apparait.



private



string
[] tabFacture =

new



string
[] { {

"IPOD"
}, {

"Headset"
}, {

"DVD"
}, {

"Webcam"
}, {

"CD"
} };


private



int
[] tabFacture1 =

new



int
[] { { 350 }, { 80 }, { 20 }, { 30 }, { 20 } };


public
Form1(){

InitializeComponent();

}

je croi avoire besoin d'une boucle du genre

for


(

int
compteur =0; compteur < tabFacture.Length; compteur++)

c tous ce que je sais pour l instant...
je vous remercie a l avance.

2 réponses

Lutinore Messages postés 3246 Date d'inscription lundi 25 avril 2005 Statut Membre Dernière intervention 27 octobre 2012 41
12 févr. 2007 à 07:50
Salut, je suis partis sur une piste un peu différente qui te montre comment faire de la liaison de données sur tes contrôles mais je pense que ça correspond à ce que tu veux faire :

public partial class Form1 : Form
{
    private struct Article
    {
        private string nom;
        private int prix;


        public string Nom
        {
            get { return nom; }
            set { nom = value; }
        }


        public int Prix
        {
            get { return prix; }
            set { prix = value; }
        }


        public Article( string nom, int prix )
        {
            this.nom = nom;
            this.prix = prix;
        }
    }


    public Form1( )
    {
        InitializeComponent( );


        Article[ ] articles =
        {
            new Article( "IPod", 350 ),
            new Article( "Headset", 80 ),
            new Article( "DVD", 20 ),
            new Article( "Webcam", 30 ),
            new Article( "CD", 20 ),
        };


        ComboBox cb = new ComboBox( );
        cb.Dock = DockStyle.Top;
        cb.DataSource = articles;
        cb.DisplayMember = "Nom";
        cb.ValueMember = "Prix";


        TextBox tb1 = new TextBox( );
        tb1.Dock = DockStyle.Bottom;
        tb1.DataBindings.Add( new Binding( "Text", cb, "Text" ) );


        TextBox tb2 = new TextBox( );
        tb2.Dock = DockStyle.Bottom;
        tb2.DataBindings.Add( new Binding( "Text", cb, "SelectedValue" ) );


        this.Controls.AddRange
        (
            new Control[ ] { cb, tb1, tb2 }
        );
    }
}
3
SinXJon Messages postés 4 Date d'inscription mardi 5 décembre 2006 Statut Membre Dernière intervention 13 février 2007
13 févr. 2007 à 04:48
tres interessant... l'utilisation de classe.
et oui sa correspond bien a ce que je cherche seulement j ai réussis à faire de la maniere
que j essayais de faire au tout debut. J'ai fait tous simplement comme ceci:

namespace

Facture{

public
partial
class
Form1 :
Form{

string[] tabFacture =
new
string[] {
"IPOD",
"Headset",
"DVD",
"Webcam",
"CD" };

int[] tabFacture1 =
new
int[5] { 350, 80 , 20, 30 , 20};

int[] tabFacture2 =
new
int[5] { 1, 2, 3, 4, 5 };

public Form1(){

InitializeComponent();

}

private
void comboBox1_SelectedIndexChanged(
object sender,
EventArgs e){

for (
int compteur =0; compteur < tabFacture.Length; compteur++){
if (comboBox1.Text Convert.ToString(tabFacture2[compteur])){txtDes.Text tabFacture[compteur];

txtprix.Text =

string.Format(
"{0:c}", tabFacture1[compteur]);}

}

}

et sa fonctionne a merveille :D:D:D , alors jte remercie quand meme c'est vraiment apprecier.
0
Rejoignez-nous