StringCollection property loses value

  • Thread starter Thread starter Nicholas Paldino [.NET/C# MVP]
  • Start date Start date
N

Nicholas Paldino [.NET/C# MVP]

Juan,

Where are you declaring your code that initializes this string
collection? It's possible that this is being written over when you open the
form again.

Hope this helps.
 
Hi all:

I have a StringCollection property like this:

public class FormExito : Form
{
................
................
private StringCollection FEditar;
[Editor("System.Windows.Forms.Design.StringCollectionEditor,
System.Design", System.Drawing.Design.UITypeEditor, System.Drawing")]
public StringCollection Editar
{
get{ return FEditar; }
set{ FEditar = value; }
}
................
................
}

It works well in design time, but after close and open the form again the
property loses the value ...

Thanks
Juan Francisco ...
 
Juan,

Well, every time you set the property on your instance, you don't have
anyplace to have code exported to store the value. For example, you should
have an InitializeComponent method that is called in your constructor. This
method is written to by the IDE to store changes made in the property grid.
 
Thanks Nicholas:

Here is the full source code(i am new with c# and i am translating this
class from delphi) , Do i need to add something?.

public class FormExito : Form
{

private StringCollection FEditar;
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("System.Windows.Forms.Design.StringCollectionEditor,
System.Design", "System.Drawing.Design.UITypeEditor, System.Drawing")]
public StringCollection Editar
{
get{ return FEditar; }
set{ FEditar = value; }
}

public FormExito()
{
FEditar = new StringCollection();
}

}

Juan Francisco ...
 
Thank you for your answer Nicholas, but I think that I will need an example,
I have been looking for something like this in internet since yesterday, but
i cannot find anything. Does anybody knows where I can find it?

Juan Francisco ...
 
Back
Top