Bonsoir, comment faire pour centraliser cette partie de code avec l'utilisation d'une liste générique.
1 2 3 4
| DG.DataSource = null;
var source = new BindingSource();
source.DataSource = Lcls.lc;
DG.DataSource = source; |
voilà mon code source que j'insère et mon problème se localise au fichier MyData.cs
MyData.cs
1 2 3 4 5 6 7 8 9 10 11
| class MyData:clslistes<Object>
{
public void RemplirDataGridList(DataGridView DG,clslistes<Object> Lcls)
{
DG.DataSource = null;
var source = new BindingSource();
source.DataSource = Lcls.lc;
DG.DataSource = source;
}
} |
clslistes.cs
1 2 3 4 5 6 7 8
| abstract class clslistes<T>
{
public static List<T> lc = new List<T>();
public clslistes()
{
}
} |
clsClient.cs
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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
| class clsClient:clslistes<clsClient>
{
private int _NumCl;
public int Numero
{
get { return _NumCl; }
set { _NumCl = value; }
}
private string _NomCl;
public string GETSETNomCl
{
get { return _NomCl; }
set { _NomCl = value; }
}
private string _telCl;
public string GETSETTelCl
{
get { return _telCl; }
set { _telCl = value; }
}
private string _adressCl;
public string GETSETadressCl
{
get { return _adressCl; }
set { _adressCl = value; }
}
private string _EmailCl;
public string GETSETEmailCl
{
get { return _EmailCl; }
set { _EmailCl = value; }
}
private string _VilleCl;
public string GETSETvilleCl
{
get { return _VilleCl; }
set { _VilleCl = value; }
}
private string _paysCl;
public string GETSETpaysCl
{
get { return _paysCl; }
set { _paysCl = value; }
}
public clsClient()
{}
public clsClient(int NumCl, string NomCl, string telCl, string adressCl, string EmailCl, string VilleCl, string paysCl)
{
this._NumCl = NumCl;
this._NomCl = NomCl;
this._adressCl = adressCl;
this._telCl = telCl;
this._EmailCl = EmailCl;
this._VilleCl = VilleCl;
this._paysCl = paysCl;
}
public bool rechercheClient(int num)
{
foreach (clsClient cl in lc)
{
if (cl.Numero == num)
return true;
}
return false;
}
public bool ajoutclient(clsClient cl)
{
if (this.rechercheClient(cl.Numero) == false)
{
lc.Add(cl);
return true;
}
return false;
}
private int rechercheclientposit(int num)
{
clsClient cl = new clsClient();
for (int i = 0; i < lc.Count; i++)
{
cl = (clsClient)lc[i];
if (cl.Numero == num)
{
return i;
}
}
return -1;
}
public bool modifierclient(int numcl,clsClient Ncli)
{
if (this.rechercheclientposit(numcl) == -1)
return false;
else
{
lc[rechercheclientposit(numcl)] = Ncli;
return true;
}
}
public bool supprimerClient(int num)
{
if (this.rechercheclientposit(num) == -1)
return false;
else
{
lc.RemoveAt(rechercheclientposit(num));
return true;
}
}
} |
sachant que l'erreur se localise exactement dans ce ligne de fichier MyData.cs:
source.DataSource = Lcls.lc;
Partager