Hello,
First off, I hope that stateful is the correct word for what I'm trying to describe!
I'm working on a user control (control A) that contains many controls within it (textboxes, a radio button, listboxes, comboboxes and a button - as well as a whack of labels). During a stage in the application, the form that contains the user control (form A, just say) is hidden when another form (form B) appears, and it can be re-dislayed by closing the form B. That's all find and good, except that form A does not retain the values inside control A. Control A's class is marked with <Serializable()> and I would assume that the controls within would be serializable as well (textboxes I'd be surprised if they weren't....), so what would I be missing So what happens is that control A is on form A and when the user runs form B, form A is hidden, and when form B closes, form A returns, but all the controls that are in control A lose their value (there are other controls on form A, such as textboxes, and they retain their value). Control A inherits from System.Windows.Forms.UserControl. What am I missing What did I do wrong This is in VS2003, using VB.NET. Please help! (... and thank you!)
I've posted this also in the Visual Basic General forum, but I haven't recieved any responses (or questions!) from there yet, so I thought that maybe I should expand my exposure. Maybe one of these posts is in the wrong place, I'm not sure. If it is, I really don't mind it being (either ignored or) deleted. Thank you!

Controls within a User Control not "stateful"
vinnu
Hello,
I am hiding Form A, and then shoing it again. In the interim, I found a so-called work-around. I don't use listboxes.
I wasn't aware that when you SHOWED a form that was HIDDEN, it fired the LOADs on all the controls again. When I found that out, I solved one of my problems, but that gave me a few more. When ended up happening is that the listbox would remember the first selection made, but not the rest, and if there was nothing selected, it would select the first item in the listbox (thankfully we inserted a blank line so it wouldn't corrupt the use of the control, but it still looked really ugly!). In order to solve this problem, I ended up removing all the listboxes from the control and inserting a third-party grid that contained two column, an ID and a description, where the ID was invisible. That seemed to work without a problem. Why would this be I'm okay with the LOAD firing again, fine, whatever, easy enough to deal with, but why doesn't the listbox remember all the selections made Why does it always have to have the first item selected when there was none before (I read some issues with that eslewhere, where the solution was just to loop through the listboxes and unselect the first item twice... seems like there's not a very good implementation of the WinForms listbox for us to use... I've used the web one for years, and I found it to be MUCH more stable and intuitive, and it doesn't have these... oddities) I didn't try it out in a stand-alone project, but I figured - if the grid works without a problem and with hardly touching the code (nothing to do with display, more with how I fill the grid initially and read data out from the grid instead of a listbox) - why would the 3rd party control work so much better Why doesn't the listbox function either as expected or as it does in WebForms
Listen to me ramble... at least it's working now! Yay!
Thanks for your time!
Leboute
When I read this, it didnt sound right, so I created a test project. The load event does NOT fire a second time when a hidden form is shown, either for the form itself or for its child controls. If you are observing this behavior, you must be doing something else wrong. I would recommend trying to reproduce the situation in a standalone project, using the same code to hide and show the form. If you want, you can also post the code here.
MichaelLee
Jaswinder Singh Kohli
LouArnold
See, I thought the same thing, that's why I was so surprised when it happened like that. I just ran the project... there might be something else wrong, but I wouldn't even know where to start looking. When I place a break point on the controls' Load, and inspect the call stack, there are only three items in it. The first item is, of course, the Load on the control. The second item is a ToolClick event on the Report Viewer form, and when viewing that it contains:
Case TB_STARTOVER
If Not Me.CalledByForm Is Nothing Then
Me.CalledByForm.Show() '<-- this is the line I'm going to refer to in a moment...mRetry =
True Me.Close() Me.CalledByForm.BringToFront() End Ifwhere the ToolClick event is sitting on the Me.CalledByForm.Show() line. The third line is sitting in Sub Main() and points to this line:
System.Windows.Forms.Application.Run(frmStartDef)
which seems to be rather inconsequential to me considering this conversation.
This seem to be really strange, and now I am very interested in testing it out at home some. And here, I just reformatted my system so I don't yet have VS.NET on it, ha ha... oi. Well, no time like the present, I suppose! But even if I can't reproduce the effect at home regarding the Load event, I would be curious to know if you could replicate the other things that were bothering me, such as the listbox only remembering the first item on the list and it always wanting to select the first item when Showing the form when there was nothing selected before I know we haven't overriden the listbox's functionality, because I just joined this project just over two months ago (it's been going for well over a year...), and nobody else ever wanted to create a user control, for whatever reason (something to do with them being non-standard controls, which therefore would not work in the Admin tool that we have that manages a whack of information regarding reports... ummm... I'm glad that I didn't believe it, LOL). Listen to me ramble again... "quarter for my life story " Just kidding. :)
It might be a while before I get around to doing this at home considering how busy it is here - getting ready for a wedding and a house and a honeymoon to someplace sunny (ergo, we've been spending a lot of time attempting to condition our skin to UV rays...), they're all coming up quick - but I hope to be able to do it this week sometime.
Thanks for your help and time!
PS: Yeah, I know - mRetry=True doesn't tell us what type the variable is, just that it's a global variable for this form... it'd drive me nuts too, but I'm already there...