How to Access a Public Property Value on all the windows forms?

Posted by Raj.Trivedi under C# on 3/20/2013 | Points: 10 | Views : 876 | Status : [Member] [MVP] | Replies : 1
Hello Team,

I have created a Property such as

public string ApplicationLevelMode;
public string SchoolMode
{
set {ApplicationLevelMode = value;}
get {return ApplicationLevelMode;}
}

Now i have a combo box and assigning the selected value of the combo box to the above proprty

private void BindDropdown()
{
DataTable dtSchool = new DataTable();
dtSchool.Columns.Add("Text", typeof(string));
dtSchool.Columns.Add("Value", typeof(string));
dtSchool.Rows.Add("---------Select---------", "0");
dtSchool.Rows.Add("Presentation Convent School", "8");
dtSchool.Rows.Add("Aparna Educational Trust", "9");
cmbSchool.DataSource = dtSchool;
cmbSchool.DisplayMember = "Text";
cmbSchool.ValueMember = "Value";
cmbSchool.SelectedIndex = 0;
}

private void SchoolSelection_Load(object sender, EventArgs e)
{
BindDropdown();
}

private void btnSubmit_Click(object sender, EventArgs e)
{
if (cmbSchool.SelectedIndex > 0)
{
this.ApplicationLevelMode = cmbSchool.SelectedValue.ToString();
MDI objMDI = new MDI();
this.Hide();
objMDI.Show();
}
else
{
MessageBox.Show("Please select school first!");
}
}

Now on Second Form i want to use this variable and pass it as a Parameter to the function.
I am doing it as creating an object of the form globally and trying to access the value directly on the function on a button click event this.ApplicationLevelMode = cmbSchool.SelectedValue.ToString(); this is in different form


frmss objss = new frmss()


code of button click where i am trying to get the value

private void SaveClass(string mode)
{
IList<string> lstvalues = new List<string>();
try
{
lstvalues.Add(mode);
lstvalues.Add(Convert.ToString(xClassID));
lstvalues.Add(xtxtClass.Text.Trim());
lstvalues.Add("1");
objmaster.InsertClass(lstvalues, objSS.ApplicationLevelMode) ; // this value is coming null.I want to get the value that is assigned in
MessageBox.Show("Data Saved");
Clear();

}
catch (Exception ex)
{
errdesc = ex.Message;
MessageBox.Show(errdesc);
xtxtClass.Focus();
}

Regard's
Raj.Trivedi
"Sharing is Caring"
Please mark as answer if your Query is resolved



Responses

Posted by: Santhi on: 3/21/2013 [Member] Starter | Points: 25

Up
0
Down
Hi

Refer this link:
http://www.codeproject.com/Articles/14122/Passing-Data-Between-Forms


Thanks & Regards,
Santhi .V

Raj.Trivedi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response