Tech
Forums
Jobs
Books
Events
Videos
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
1
Answer
use of generic list
abdelwaheb ammar
8y
500
1
Reply
hello,how to centralize that part of code with the use of a generic list.
DG.DataSource =
null
;
var source =
new
BindingSource();
source.DataSource = Lcls.lc;
DG.DataSource = source;
that is my source code I insert and my problem is localized in MyData.cs file
MyData.cs
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
abstract
class
clslistes<T>
{
public
static
List<T> lc =
new
List<T>();
public
clslistes()
{
}
}
clsClient.cs
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
;
}
}
}
knowing that the error is localized exactly in this line MyData.cs file:
source.DataSource = Lcls.lc;
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
what will happens if one of the packet get lost in DHCP?
2 bin packing solution