mercredi 15 octobre 2014

Share a dictionary within a C# windows form


Vote count:

0




I have a form with a series of buttons. button4 has to load some data from Excel and store the information into a dictionary called dataMap



private void button4_Click(object sender, EventArgs e)
{
loadXL myMap = new loadXL();
Dictionary<string, marketdata> dataMap = myMap.myDataLoader(Convert.ToDateTime(AsOfDate.Text),Convert.ToDouble(Underlying.Text));
}


This code generates correctly the dictionary and all the data I need are stored in dataMap . Now the problem is that I need the information in the dictionary to be accessible when I click another button. In order to do that I have tried the following:



public Dictionary<string, marketdata> button4_Click(object sender, EventArgs e)
{
loadXL myMap = new loadXL();
Dictionary<string, marketdata> dataMap = myMap.myDataLoader(Convert.ToDateTime(AsOfDate.Text),Convert.ToDouble(Underlying.Text));

return dataMap;
}


So the click button event now should return the dictionary dataMap . If I run this I get the following error:


'System.Collections.Generic.Dictionary Project2.myInputForm.button4_Click(object, System.EventArgs)' has the wrong return type


and it refers to the following line in the form designer:



this.button4.Click += new System.EventHandler(this.button4_Click);


How can I handle this? Is there a quick way to make the dictionary built when clicking button4 accessible by other button clicks?


Thanks.



asked 42 secs ago

opt

9






Share a dictionary within a C# windows form

Aucun commentaire:

Enregistrer un commentaire