Passing data between parent, child and class
-
Howdey, I have been digging into the issue of delegates and tried to implement http://www.colinmackay.net/Articles/PassingValuesBetweenFormsinNET/tabid/58/Default.aspx[^] but I am missing something. Background, I have got a parent "frmMDI" who creates a new instance of class ReadModel readMdl = new ReadModel;"
class ReadModel { private string strModelDesc1 = "Model"; private int intNLAY = 1; public bool SaveModelData(string strOpenFile) { etc etc } public string inModel { get { return strModelDesc1; } set { strModelDesc1 = value; } } }
Then the frmMDI calls a new instance of a child frmData that has textboxes etc allowing the user to give new values for strModelDesc1 and intNLAY. This must then be saved later to a file. The problem that I have is setting the new values from the user on frmData back to the specific instance of class readMdl in frmMDI so that that specific instance of SaveModelData can save to a file and other classes can use it later on by reading readMdl.inModel etc. I can still get the info from the child (while it is open) get and set blocks but once it is closed then it is lost. thanks for the patience Ian I could use static variables all the way but that would be stupid.
-
Howdey, I have been digging into the issue of delegates and tried to implement http://www.colinmackay.net/Articles/PassingValuesBetweenFormsinNET/tabid/58/Default.aspx[^] but I am missing something. Background, I have got a parent "frmMDI" who creates a new instance of class ReadModel readMdl = new ReadModel;"
class ReadModel { private string strModelDesc1 = "Model"; private int intNLAY = 1; public bool SaveModelData(string strOpenFile) { etc etc } public string inModel { get { return strModelDesc1; } set { strModelDesc1 = value; } } }
Then the frmMDI calls a new instance of a child frmData that has textboxes etc allowing the user to give new values for strModelDesc1 and intNLAY. This must then be saved later to a file. The problem that I have is setting the new values from the user on frmData back to the specific instance of class readMdl in frmMDI so that that specific instance of SaveModelData can save to a file and other classes can use it later on by reading readMdl.inModel etc. I can still get the info from the child (while it is open) get and set blocks but once it is closed then it is lost. thanks for the patience Ian I could use static variables all the way but that would be stupid.
One part of the article you linked talks about passing information between forms using properties, like the example you provided, and towards the end the article provides examples of using delegates and events to pass info between forms. My suggestion is that you use delegates and events, instead of properties, and raise the event in the child form as the child is closing (in the FormClosing event) so that the information gets returned to the parent form at that time, instead of being lost on the close. Or, as an alternative, you could raise the event whenever the text is actually changed, and make the changes to the database each time the text is changed. If you did try the delegates/events example, and had problems with that, please describe what problem/error you were receiving.