|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
make a form shared - called from another form - how?I have a child form in an Mdi Parent form. I have 5 menu buttons on the Parent that I use to show the child form. Originally, in the Parent form on load event I had this line of code frmChild.MdiParent = Me But then, I added an argument to the constructor of the child form. Now I get the error message for the line of code frmChild.MdiParent = Me. Error say: "Reference to a non-shared member requires and Object Reference" So in each of the Menu buttons I now have Dim frm As New frmChild frm.MdiParent = Me frm.Show I want to eliminate the redundant line of code frm.MdiParent = Me. How do I make the Child form shared? I tried placing the word "Shared" next to the constructor of frmchild, but got an error. How to make the form shared? Thanks, Rich The error you're getting means that you're referring to a class, not an
object. In your message, you mention that the error comes on this line: > frmChild.MdiParent = Me But then in your quoted code, you use> Dim frm As New frmChild Note the difference: frm is an instance, frmChild is a class. So the> frm.MdiParent = Me first snippet doesn't make sense: "frmChild" is a class, not an instance of a class. I'm unclear about what you mean about adding an argument to the constructor... do you mean that you pass a form reference to the child form and have it set its own MdiParent property? You could do that, sure; in the overloaded New() sub, pass a reference to the parent as a parameter and then set Me.MdiParent = theParameter It's worth noting that in VB6, frmChild referred both to the form "class" *and* to a default instance of the form; a lot of transitioning coders run into this problem. Hope that helps. g. Thank you for your reply. This is very informative. Now to explain a little
more what I am doing: I have one parent MDI form and one child form. I am using the Parent MDI form to take advantage of the scroll bars because the user of my app has a resolution that really restricts screen realestate - thus the scroll bars (I have several pannels and splitters, ... on the child form - did not want to bother with scrollbars). The child form gets data from our sql server. Each menu button on the parent form passes a param to the child form to pick up different rows from sql server. With each menu button on the Parent mdi, I close the child form and re-open it as new. From what you are suggesting, I get the idea that I do not need to keep reloading the child form. I would rather load the child form once and pass the parameter to it from the parent through the menubutton - but I have to reload the data. I tried using a public sub - which I was able to reload the data by invoking it from the parent, but the datagrids on the child did not refresh/update. The only way I was able to get the datagrids on the child to refresh/update was to close child and reopen child with the new parameter. Is there a way I could open the child form once and reload/refresh the data from the Parent Mdi form without having to reopen the child form? Thanks, Rich Show quoteHide quote "Graham Charles" wrote: > The error you're getting means that you're referring to a class, not an > object. In your message, you mention that the error comes on this line: > > > frmChild.MdiParent = Me > > But then in your quoted code, you use > > > Dim frm As New frmChild > > frm.MdiParent = Me > > Note the difference: frm is an instance, frmChild is a class. So the > first snippet doesn't make sense: "frmChild" is a class, not an > instance of a class. I'm unclear about what you mean about adding an > argument to the constructor... do you mean that you pass a form > reference to the child form and have it set its own MdiParent property? > You could do that, sure; in the overloaded New() sub, pass a reference > to the parent as a parameter and then set > > Me.MdiParent = theParameter > > It's worth noting that in VB6, frmChild referred both to the form > "class" *and* to a default instance of the form; a lot of transitioning > coders run into this problem. > > Hope that helps. > > g. > > You shouldn't have to reload your child form, no... you just need a
procedure that refreshes the data on the child form. g. I am the slow one. I finally figured out what you meant about passing a
reference to the child form of the Parent in the overloaded constructor of th child form. That is working. Except VB2005 is passing it ByVal instead of ByRef. Don't know if that makes any difference. The app seems to work OK. Show quoteHide quote "Graham Charles" wrote: > The error you're getting means that you're referring to a class, not an > object. In your message, you mention that the error comes on this line: > > > frmChild.MdiParent = Me > > But then in your quoted code, you use > > > Dim frm As New frmChild > > frm.MdiParent = Me > > Note the difference: frm is an instance, frmChild is a class. So the > first snippet doesn't make sense: "frmChild" is a class, not an > instance of a class. I'm unclear about what you mean about adding an > argument to the constructor... do you mean that you pass a form > reference to the child form and have it set its own MdiParent property? > You could do that, sure; in the overloaded New() sub, pass a reference > to the parent as a parameter and then set > > Me.MdiParent = theParameter > > It's worth noting that in VB6, frmChild referred both to the form > "class" *and* to a default instance of the form; a lot of transitioning > coders run into this problem. > > Hope that helps. > > g. > >
Wrapper classes
Windows Service using VB.Net automatic startup problem ! preventing default value in vb.net catch the process terminate from the task manager FAST date string conversion ? Best Suite Documentation playing & re-playing 7 .wav files How To Force Copy One File To Another Resizing Automating restart of PC |
|||||||||||||||||||||||