Classe petite question facile merci

Résolu
iian2 Messages postés 103 Date d'inscription jeudi 10 novembre 2005 Statut Membre Dernière intervention 21 septembre 2007 - 13 juil. 2007 à 15:46
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 - 14 juil. 2007 à 10:26
Allo,

J'ai une petite question mettons que j'ai une class:

Personne

plus bas apres mes get set et tout

public

Personne(
int NewMIntIdPersonne,
string NewMStrName){

MIntIdPersonne = NewMIntIdPersonne;

MStrName = NewMStrName;

}

 CPersonne : CollectionBase

public

void AddPersonne(Personne NewPersonne){

List.Add(NewPersonne);

}

Comment je vais apartir de ma winform pour pouvoir rajouter un element a ma collection ?

Genre :

//private Personne CPersonne;

//ColPersonne = new CPersonne();

//ColPersonne.AddPersonne(new Personne(1,"allotoi"));

De mon coder ca marche pas alors me dire comment faire svp merci

Ian

4 réponses

iian2 Messages postés 103 Date d'inscription jeudi 10 novembre 2005 Statut Membre Dernière intervention 21 septembre 2007
13 juil. 2007 à 17:05
J<ai trouver :)

merci a tous

ian
3
bernie666 Messages postés 427 Date d'inscription mercredi 1 octobre 2003 Statut Membre Dernière intervention 29 janvier 2008 1
13 juil. 2007 à 16:08
euh ...
dans ta classe tu creer une nouvelle instance de CPersonne

ex CPersonne collectionPersonne = new CPersonne();
et apres
collectionPersonne.Add(New Personne(1,"toto");

Sinon tu peux utiliser des List génériques

List maList = new List();

maList.Add(New Personne(1,"toto"));

Bonne journée
-------------------------------------------http://quoideneufaujourdhui.spaces.live.com
0
iian2 Messages postés 103 Date d'inscription jeudi 10 novembre 2005 Statut Membre Dernière intervention 21 septembre 2007
13 juil. 2007 à 16:18
Ca marche pas veux tu mon code au complet ?

Class:
using

System;
using

System.Collections;
namespace

Testmoi{

///<summary>

/// Summary description for Personne.

///</summary>

public
class Personne{

//private Personne CPersonne;

//private CPersonne ColPersonne;

public Personne(){

//ColPersonne = new CPersonne();

//ColPersonne.AddPersonne(new Personne(1,"Ian"));

//ColPersonne.AddPersonne(new Personne(2,"Mario"));}

int MIntIdPersonne;

string MStrName;

public
int IntIdPersonne{

get{

return MIntIdPersonne;}

set{

MIntIdPersonne =

value;}

}

public
string StrName{

get{

return MStrName;}

set{

MStrName =

value;}

}

public Personne(
int NewMIntIdPersonne,
string NewMStrName){

MIntIdPersonne = NewMIntIdPersonne;

MStrName = NewMStrName;

}

//Collection the dbVss

public
class CPersonne : CollectionBase{

public
void AddPersonne(Personne NewPersonne){

List.Add(NewPersonne);

}

public
void RemovePersonne(Personne ByePersonne){

List.Remove(ByePersonne);

}

public Personne
this[
int PersonneIndex]{

get{

return (Personne)List[PersonneIndex];}

set{

List[PersonneIndex] =

value;}

}

}

}

}

Form:

using

System;
using

System.Drawing;
using

System.Collections;
using

System.ComponentModel;
using

System.Windows.Forms;
using

System.Data;
namespace

Testmoi{

///<summary>

/// Summary description for Form1.

///</summary>

public
class FrmMain : System.Windows.Forms.Form{

private System.Windows.Forms.Button BtnAdd;

private System.Windows.Forms.TextBox TxtId;

private System.Windows.Forms.TextBox TxtName;

private System.Windows.Forms.DataGrid dataGrid1;

private System.Windows.Forms.Button BtnUpdate;

///<summary>

/// Required designer variable.

///</summary>

private System.ComponentModel.Container components =
null;

public FrmMain(){

//

// Required for Windows Form Designer support

//InitializeComponent();

//

// TODO: Add any constructor code after InitializeComponent call

//}

///<summary>

/// Clean up any resources being used.

///</summary>

protected
override
void Dispose(
bool disposing ){

if( disposing ){

if (components !=
null) {

components.Dispose();

}

}

base.Dispose( disposing );}

#region

Windows Form Designer generated code

///<summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

///</summary>

private
void InitializeComponent(){

this.BtnAdd =
new System.Windows.Forms.Button();

this.TxtId =
new System.Windows.Forms.TextBox();

this.TxtName =
new System.Windows.Forms.TextBox();

this.dataGrid1 =
new System.Windows.Forms.DataGrid();

this.BtnUpdate =
new System.Windows.Forms.Button();((System.ComponentModel.ISupportInitialize)(

this.dataGrid1)).BeginInit();

this.SuspendLayout();

//

// BtnAdd

//

this.BtnAdd.Location =
new System.Drawing.Point(104, 120);

this.BtnAdd.Name = "BtnAdd";

this.BtnAdd.TabIndex = 0;

this.BtnAdd.Text = "Add";

this.BtnAdd.Click +=
new System.EventHandler(
this.BtnAdd_Click);

//

// TxtId

//

this.TxtId.Location =
new System.Drawing.Point(64, 48);

this.TxtId.Name = "TxtId";

this.TxtId.Size =
new System.Drawing.Size(160, 20);

this.TxtId.TabIndex = 1;

this.TxtId.Text = "";

//

// TxtName

//

this.TxtName.Location =
new System.Drawing.Point(64, 80);

this.TxtName.Name = "TxtName";

this.TxtName.Size =
new System.Drawing.Size(160, 20);

this.TxtName.TabIndex = 2;

this.TxtName.Text = "";

//

// dataGrid1

//

this.dataGrid1.DataMember = "";

this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;

this.dataGrid1.Location =
new System.Drawing.Point(8, 208);

this.dataGrid1.Name = "dataGrid1";

this.dataGrid1.Size =
new System.Drawing.Size(280, 232);

this.dataGrid1.TabIndex = 3;

//

// BtnUpdate

//

this.BtnUpdate.Location =
new System.Drawing.Point(88, 152);

this.BtnUpdate.Name = "BtnUpdate";

this.BtnUpdate.Size =
new System.Drawing.Size(112, 23);

this.BtnUpdate.TabIndex = 4;

this.BtnUpdate.Text = "Update";

//

// FrmMain

//

this.AutoScaleBaseSize =
new System.Drawing.Size(5, 13);

this.ClientSize =
new System.Drawing.Size(296, 461);

this.Controls.Add(
this.BtnUpdate);

this.Controls.Add(
this.dataGrid1);

this.Controls.Add(
this.TxtName);

this.Controls.Add(
this.TxtId);

this.Controls.Add(
this.BtnAdd);

this.Name = "FrmMain";

this.Load +=
new System.EventHandler(
this.FrmMain_Load);((System.ComponentModel.ISupportInitialize)(

this.dataGrid1)).EndInit();

this.ResumeLayout(
false);}

#endregion

///<summary>

/// The main entry point for the application.

///</summary>[STAThread]

static
void Main() {

Application.Run(

new FrmMain());}

private
void FrmMain_Load(
object sender, System.EventArgs e){

}

private Personne CPersonne;

//private CPersonne ColPersonne;

private
void BtnAdd_Click(
object sender, System.EventArgs e){

CPersonne ColPersonne =

new CPersonne();ColPersonne. (Icic je vois rien quand je met le .)

 

/*if (TxtId.Text != null || TxtName != null){

ColPersonne.AddPersonne(new Personne(TxtId.Text,TxtName.Text));

}

else

{

MessageBox.Show("Vous devez remplir les champs");

}*/

}

}

}

Merci d<avance

Ian
0
cs_coq Messages postés 6349 Date d'inscription samedi 1 juin 2002 Statut Membre Dernière intervention 2 août 2014 101
14 juil. 2007 à 10:26
Et la réponse est ?

/*
coq
MVP Visual C#
CoqBlog
*/
0
Rejoignez-nous