Click here to Skip to main content
15,890,973 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello I have a really stupid question
but gonna ask anyway :)

on formLoad event I have this

string datacompany = rm.GetString("datacompany");

and I use this datacompany later on in formLoad, but I have to use this datacompany on buttonClick event also, and I dont want to make this string again but want to call datacompany,
Stupid question, is how to do this :( I know really stupid
Posted
Comments
walterhevedeich 31-May-13 6:16am    
Declare it within your Form class, and then on it's constructor, you initialize the string.

You need to use properties[^].

C#
private string datacompany;
public string DataCompany{
  set{
    datacompany = value;
  }
  get{
    return datacompany;
  }
}


then call
C#
DataCompany = rm.GetString("datacompany");


hope this helps.
 
Share this answer
 
Comments
shonezi 31-May-13 6:22am    
thank you, sorry for stupid question, but my brain has left me this morning :P
Declare it as member of the form class (instead of local of the formLoad method).
If you are using it in the form class itself then you don't need to declare it as public.

C#
public partial class MyForm : Form
{
  string datacompany;
   //...



C#
private void MyForm_Load(object sender, EventArgs e)
{
  datacompany = rm.GetString("datacompany");
  //..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900