usercontrol properties

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i'm developing an usercontrol that should have a property that must be an array of a struct
so i wrote this struct

public struct DatiCamp

[Category("Dati")
private string _nome
public string Nom

get{return(this._nome);
set{this._nome = value;

private string _intestazione
public string Intestazion

get{return(this._intestazione);
set{this._intestazione = value;

private int _larghezza
public int Larghezz

get{return(this._larghezza);
set{this._larghezza = value;

[Category("Componente")
private string _name
public string Nam

get{return(this._name);
set{this._name = value;



then i defined my propert

private DatiCampo[] _campi
public DatiCampo[] DBCamp

get{return(this._campi);
set{this._campi=value;


but when i use it in VS.NET 2003 at design time, i can set some values from properties page, but after i click OK an
reopen this property the values was lost;

i try to "mark" my prop wit
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)

but VS.NET always lost my values! why? am i doing some mistakes

thanks a lot
 
I remember I've already answered to your question on italian newsgroup.

All you have to do is to initialize the array behind your property DBCampi,
that is the array "_campi". You can do this in the constructor of your
class, but a better place would be the "get" accessor of the property
DBCampi.

Substitute the implementation of the property DBCampi with the following
one, and you'll see that everything works fine.Don't forget to recompile
your project.

public DatiCampo[] DBCampi
{
get{
if(_campi==null)
{
_campi=new DatiCampo[1];
_campi[0]=new DatiCampo();
_campi[0].Name="Pippo1";
}
return(this._campi);
}
set{this._campi=value;}
}

Ernest




Luca Beretta said:
i'm developing an usercontrol that should have a property that must be an array of a struct;
so i wrote this struct

public struct DatiCampo
{
[Category("Dati")]
private string _nome;
public string Nome
{
get{return(this._nome);}
set{this._nome = value;}
}
private string _intestazione;
public string Intestazione
{
get{return(this._intestazione);}
set{this._intestazione = value;}
}
private int _larghezza;
public int Larghezza
{
get{return(this._larghezza);}
set{this._larghezza = value;}
}
[Category("Componente")]
private string _name;
public string Name
{
get{return(this._name);}
set{this._name = value;}
}
}

then i defined my property

private DatiCampo[] _campi;
public DatiCampo[] DBCampi
{
get{return(this._campi);}
set{this._campi=value;}
}

but when i use it in VS.NET 2003 at design time, i can set some values
from properties page, but after i click OK and
reopen this property the values was lost;

i try to "mark" my prop with
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]

but VS.NET always lost my values! why? am i doing some mistakes ?

thanks a lot
 
Back
Top