abdelwaheb ammar

abdelwaheb ammar

  • 1.3k
  • 393
  • 118.6k

use of generic list

Oct 19 2016 8:18 PM
hello,how to centralize that part of code with the use of a generic list.
  1. DG.DataSource = null;  
  2.            var source = new BindingSource();  
  3.            source.DataSource = Lcls.lc;  
  4.            DG.DataSource = source;  
 that is my source code I insert and my problem is localized in MyData.cs file
MyData.cs 
  1. class MyData:clslistes<Object>  
  2.     {  
  3.    
  4.         public void RemplirDataGridList(DataGridView DG,clslistes<Object> Lcls)  
  5.         {  
  6.             DG.DataSource = null;  
  7.             var source = new BindingSource();  
  8.             source.DataSource = Lcls.lc;  
  9.             DG.DataSource = source;  
  10.         }  
  11.     }  
 clslistes.cs
 
  1. abstract class clslistes<T>  
  2.     {  
  3.        public static List<T> lc = new List<T>();  
  4.        public clslistes()  
  5.        {  
  6.    
  7.        }  
  8.     }  
 clsClient.cs
 
  1. class clsClient:clslistes<clsClient>  
  2.     {  
  3.         private int _NumCl;  
  4.    
  5.         public int Numero  
  6.         {  
  7.             get { return _NumCl; }  
  8.             set { _NumCl = value; }  
  9.         }  
  10.         private string _NomCl;  
  11.    
  12.         public string GETSETNomCl  
  13.         {  
  14.             get { return _NomCl; }  
  15.             set { _NomCl = value; }  
  16.         }  
  17.         private string _telCl;  
  18.    
  19.         public string GETSETTelCl  
  20.         {  
  21.             get { return _telCl; }  
  22.             set { _telCl = value; }  
  23.         }  
  24.         private string _adressCl;  
  25.    
  26.         public string GETSETadressCl  
  27.         {  
  28.             get { return _adressCl; }  
  29.             set { _adressCl = value; }  
  30.         }  
  31.         private string _EmailCl;  
  32.    
  33.         public string GETSETEmailCl  
  34.         {  
  35.             get { return _EmailCl; }  
  36.             set { _EmailCl = value; }  
  37.         }  
  38.         private string _VilleCl;  
  39.    
  40.         public string GETSETvilleCl  
  41.         {  
  42.             get { return _VilleCl; }  
  43.             set { _VilleCl = value; }  
  44.         }  
  45.         private string _paysCl;  
  46.    
  47.         public string GETSETpaysCl  
  48.         {  
  49.             get { return _paysCl; }  
  50.             set { _paysCl = value; }  
  51.         }  
  52.         public clsClient()  
  53.         {}  
  54.    
  55.         public clsClient(int NumCl, string NomCl, string telCl, string adressCl, string EmailCl, string VilleCl, string paysCl)  
  56.         {  
  57.    
  58.             this._NumCl = NumCl;  
  59.             this._NomCl = NomCl;  
  60.             this._adressCl = adressCl;  
  61.             this._telCl = telCl;  
  62.             this._EmailCl = EmailCl;  
  63.             this._VilleCl = VilleCl;  
  64.             this._paysCl = paysCl;  
  65.    
  66.         }  
  67.    
  68.         public bool rechercheClient(int num)  
  69.         {  
  70.             foreach (clsClient cl in lc)  
  71.             {  
  72.                 if (cl.Numero == num)  
  73.                     return true;  
  74.    
  75.             }  
  76.             return false;  
  77.    
  78.         }  
  79.    
  80.         public bool ajoutclient(clsClient cl)  
  81.         {  
  82.             if (this.rechercheClient(cl.Numero) == false)  
  83.             {  
  84.                 lc.Add(cl);  
  85.                 return true;  
  86.             }  
  87.    
  88.             return false;  
  89.         }  
  90.    
  91.         private int rechercheclientposit(int num)  
  92.         {  
  93.             clsClient cl = new clsClient();  
  94.             for (int i = 0; i < lc.Count; i++)  
  95.             {  
  96.                 cl = (clsClient)lc[i];  
  97.                 if (cl.Numero == num)  
  98.                 {  
  99.                     return i;  
  100.    
  101.                 }  
  102.             }  
  103.             return -1;  
  104.    
  105.         }  
  106.    
  107.    
  108.    
  109.         public bool modifierclient(int numcl,clsClient Ncli)  
  110.         {  
  111.             if (this.rechercheclientposit(numcl) == -1)  
  112.                 return false;  
  113.             else  
  114.             {  
  115.                 lc[rechercheclientposit(numcl)] = Ncli;  
  116.                 return true;  
  117.    
  118.             }  
  119.    
  120.    
  121.         }  
  122.    
  123.         public bool supprimerClient(int num)  
  124.         {  
  125.             if (this.rechercheclientposit(num) == -1)  
  126.                 return false;  
  127.             else  
  128.             {  
  129.                 lc.RemoveAt(rechercheclientposit(num));  
  130.                 return true;  
  131.    
  132.             }  
  133.    
  134.         }  
  135.     }  
 knowing that the error is localized exactly in this line MyData.cs file:
 
  1. source.DataSource = Lcls.lc;  
 
 
 
 
 

Answers (1)