-1

New to C#; have been a VB.NET/VBA developer for years. Am currently working on an application for our off-site workers. I have a main switchboard form with a drop-down of project numbers. The user then has the ability to open a variety of form-based tools, to include a Budgets form. On change of the drop-down, I store a Program-scoped class variable, cJob which has multiple properties (customer, location, etc). On open of the Budgets form:

Form frm = new FieldBudgets.frmBudgets().Show();

I have a private static instance of cJob called meJob (new cJob). When going back to the switchboard, the user, without closing that instance of the Budgets for, can open additional instances of the same Budget form with different project numbers selected.

Here is my problem (sorry it took so long to get here): A Refresh button can update the data on the Budgets form, but the new meJob information from the last instance get carried to the other instance. How can I keep these separate? I thought the new meJob would stick with the individual instances.

As an aside, I do have a less than glamorous "solution" that involves a hidden textbox and reloading the new meJob on Refresh. If that is the best solution I get, so be it...

MJ

Erik Philips
  • 53,428
  • 11
  • 128
  • 150

1 Answers1

-1
Dictionary<string,FieldBudgets.frmBudgets> myBudgets = new Dictionary<string,FieldBudgets.frmBudgets>();
myBudgets.Add("Budget1",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget2",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget3",New FieldBudgets.frmBudgets());
myBudgets.Add("Budget4",New FieldBudgets.frmBudgets());

myBudgets["Budget2"].Show();

You might put any unique fields and/or properties in the constructor for frmBudgets.

Shannon Holsinger
  • 2,293
  • 1
  • 15
  • 21
  • Not well versed on the Dictionary (learning by Google) but I'm not following this advice. How does the instance of meJob on frmBudgets translate to a Dictionary item? Why doesn't the individual instance of the frmBudgets "remember" its specific identity? – Matthew Johnson Sep 14 '16 at 19:45
  • A Dictionary is a way of having several instances of the same object open at once and accessible by a key (which can be a string, and int or whatever unique item you want). It is easier than creating MyForm1, myForm2, myForm3, etc. – Shannon Holsinger Sep 14 '16 at 19:48
  • Okay, the concept of the dictionary makes some sense. However, not sure how that relates to a dictionary "page" knowing it's own contents if the dictionary is held and implemented on the calling page. – Matthew Johnson Sep 14 '16 at 20:33
  • You can pass page-specific data to the budget form through its constructor, or operate on any field, property, or method the same as you would an instance of the form itself. myBudgets["Budget1"].someMethod() or myBudgest["Budget2"].someProperty = value; – Shannon Holsinger Sep 14 '16 at 20:59
  • Maybe I'm not being clear: I open frmBudget(Job #123) and frmBudget (Job #234) have a variable defined that, in a VB setting, I could just say: me.JobNumber, and they would just know, "oh yeah, I'm the form holding #123". So, when it goes to refresh itself, it is using information from 123, not 234, which was opened second. – Matthew Johnson Sep 14 '16 at 21:05