abdelwaheb ammar

abdelwaheb ammar

  • 1.2k
  • 393
  • 118.8k

Displaying in DataGridView

Oct 17 2016 8:17 AM
hi, my question is about the datagridview. I create a class ctsContacts with this source code:
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.    
  6. namespace TestingListe  
  7. {  
  8.     class ctsContacts:lstContacts  
  9.     {  
  10.         private int _numero;  
  11.    
  12.         public int Numero  
  13.         {  
  14.             get { return _numero; }  
  15.             set { _numero = value; }  
  16.         }  
  17.    
  18.         private string _nom;  
  19.    
  20.         public string Nom  
  21.         {  
  22.             get { return _nom; }  
  23.             set { _nom = value; }  
  24.         }  
  25.         private string _prenom;  
  26.    
  27.         public string Prenom  
  28.         {  
  29.             get { return _prenom; }  
  30.             set { _prenom = value; }  
  31.         }  
  32.         private string _message;  
  33.    
  34.         public string Message  
  35.         {  
  36.             get { return _message; }  
  37.             set { _message = value; }  
  38.         }  
  39.    
  40.    
  41.         public ctsContacts()  
  42.         {  
  43.    
  44.         }  
  45.    
  46.         public ctsContacts(int numero, string nom,string prenom,string message)  
  47.         {  
  48.             this.Numero = numero;  
  49.             this.Nom = nom;  
  50.             this.Prenom = prenom;  
  51.             this.Message = message;  
  52.         }  
  53.    
  54.         public bool recherche(int num)  
  55.         {  
  56.             foreach (ctsContacts search in ct)  
  57.             {  
  58.                 if (search.Numero == num)  
  59.                 {  
  60.                     return false;  
  61.                 }  
  62.    
  63.             }  
  64.             return true;  
  65.    
  66.         }  
  67.    
  68.         public bool Ajouter(ctsContacts ctn)  
  69.         {  
  70.             if (this.recherche(ctn.Numero) == true)  
  71.             {  
  72.                 ct.Add(ctn);  
  73.                 return true;  
  74.             }  
  75.             return false;  
  76.         }  
  77.    
  78.     }  
  79. }  
 This class inherits another abstract class that contains a list
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.    
  6. namespace TestingListe  
  7. {  
  8.     class lstContacts  
  9.     {  
  10.         public static List<ctsContacts> ct = new List<ctsContacts>();  
  11.         public lstContacts()  
  12.         {  
  13.    
  14.         }  
  15.    
  16.     }  
  17. }  
and then in the contact form and add button at this writing source code
 
  1. private void btnajouter_Click(object sender, EventArgs e)  
  2.         {  
  3.             ctsContacts contact = new ctsContacts();  
  4.             contact.Numero = int.Parse(txtnumero.Text);  
  5.             contact.Nom = txtNom.Text;  
  6.             contact.Prenom = txtPrenom.Text;  
  7.             contact.Message = txtmesssage.Text;  
  8.    
  9.             contact.Ajouter(contact);  
  10.    
  11.             dgvcontacts.DataSource = null;  
  12.    
  13.             dgvcontacts.DataSource = ctsContacts.ct;  
  14.    
  15.         }  
 the problem is at the datagridview display that copy header right.
 
 
and bellow i upload all the project in a .rar file 

Attachment: TestingListe.rar

Answers (1)