1 pièce(s) jointe(s)
Affichage en DataGridView
salut, ma question est concernant le datagridview.je créer une classe ctsContacts avec ce code source:
Code:
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestingListe
{
class ctsContacts:lstContacts
{
private int _numero;
public int Numero
{
get { return _numero; }
set { _numero = value; }
}
private string _nom;
public string Nom
{
get { return _nom; }
set { _nom = value; }
}
private string _prenom;
public string Prenom
{
get { return _prenom; }
set { _prenom = value; }
}
private string _message;
public string Message
{
get { return _message; }
set { _message = value; }
}
public ctsContacts()
{
}
public ctsContacts(int numero, string nom,string prenom,string message)
{
this.Numero = numero;
this.Nom = nom;
this.Prenom = prenom;
this.Message = message;
}
public bool recherche(int num)
{
foreach (ctsContacts search in ct)
{
if (search.Numero == num)
{
return false;
}
}
return true;
}
public bool Ajouter(ctsContacts ctn)
{
if (this.recherche(ctn.Numero) == true)
{
ct.Add(ctn);
return true;
}
return false;
}
}
} |
ce classe herite un autre classe abtraite qui contient une liste
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TestingListe
{
class lstContacts
{
public static List<ctsContacts> ct = new List<ctsContacts>();
public lstContacts()
{
}
}
} |
et puis dans le formulaire de contact et au niveau de bouton ajouter j'ecris ce code source
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| private void btnajouter_Click(object sender, EventArgs e)
{
ctsContacts contact = new ctsContacts();
contact.Numero = int.Parse(txtnumero.Text);
contact.Nom = txtNom.Text;
contact.Prenom = txtPrenom.Text;
contact.Message = txtmesssage.Text;
contact.Ajouter(contact);
dgvcontacts.DataSource = null;
dgvcontacts.DataSource = ctsContacts.ct;
} |
le problème c'est au niveau de l'affichage de datagridview qui copier entête à droite.
Pièce jointe 222791