Hi, I have a problem when I try to share objects between forms. I have a ConfData
object in which I have several attributes that I want to update between the different forms that I have. The code is as follows:
public partial class ConfigDataViewer : UserControl
{
#region Atributos privados
/// <summary>
/// Creamos el objeto para asignar los valores de la interfaz a los datos internos
/// </summary>
ECCE_ConfigData ConfData = new ECCE_ConfigData();
TcConfig oTcConfig = new TcConfig(ConfData); -> ERROR
UvConfig oUvConfig = new UvConfig();
#endregion Atributos privados
This ConfData object is passed to another Form so that it can update a series of values and obtain them from this control. This is the code of the other way
public partial class TcConfig : Form
{
ECCE_ConfigData ConfData2 = new ECCE_ConfigData();
AñadirTc oTc = new AñadirTc();
int i = 0;
public TcConfig(ECCE_ConfigData ConfData)
{
InitializeComponent();
ConfData2 = ConfData;
}
public void buttonAñadirTc_Click(object sender, EventArgs e)
{
if (oTc.ShowDialog() == DialogResult.OK)
{
ConfData2.TcCnf.TcCnfArray[i] = new sTcCnf(Convert.ToByte(oTc.textBox_IdTc.Text), Convert.ToByte(oTc.textBox_TcType.Text), Convert.ToByte(oTc.textBox_NumUVsTc.Text), Convert.ToByte(oTc.textBox_NumUVsNormalizacion.Text), Convert.ToByte(oTc.textBox_IdUVNormalizacion.Text), Convert.ToByte(oTc.textBox_TcParamFlags.Text));
i++;
}
}
This last code is correct. The problem is that the class of the object ConfData
is not static and the error that puts me in the line that I have put ERROR
is:
Error 1 A field initializer can not reference the field, non-static method or property 'CSCI_ECCE_APP.UserControls.ConfigDataViewer.ConfData'
Does anyone know how I can solve this? I tried to make the class of the ConfData object static but it gives me a lot of errors and I prefer another solution. Thanks