Solved

Raiseevent in a form in usercontrol

Posted on 2006-07-10
6
280 Views
Last Modified: 2013-12-25
hey there.

I have a MDI form wi th toolbar. then, forms (MDI childs) that load usercontrols. few of those usercontrols may have internal forms. I want the toolbar buttons to relate to events occur in the usercontrols' forms. so where is the problem?

I declared public event in the usercontrol. but since the event itself occur in one of the usercontrol's form,  I can't raise the event.  as far as i know, I don't have access from forms to the usercontrol's variables and such. how do I that?
0
Comment
Question by:avi666
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17071900
you have to catch, in the usercontrol, a internal event of the form, from where you then can raise the usercontrol's event.
or, give the usercontrol a FRIEND sub that can raise the event, and pass the usercontrol object reference to the form so it can call that sub
If you need furhter explanations, don't hesitate to ask
0
 

Author Comment

by:avi666
ID: 17072961
hey angelIII. 10x  very much for your suggestion.
I won't hesitate to ask further explanation :)

I have a save button in the MDI toolbar and want to save changes made in the internal form of the usercontrol.

so in the MDI form i have the code:

sub toolbar_click(...)
     MDIchild.mycontrol.LogSave
end sub

in the usercontrol I have:
Public Sub LogSave()
     Call frm.SaveForm
Exit Sub

and in the frm:
Public Sub SaveForm()
...
end sub

so far, so good. the prob is that the save button is initially disabled and i want to enable it whenever a txt_change event occur in the usercontrol's form. so i added:
 
private sub mycontrol_SaveEvent
   MDImain.toolbar(SaveButton).enabled=true
end sub

and in the usercontrol declaration section:

public event SaveLog

and now I need to complete the circle with the raiseevent somewhere in some of the form's txt_change events.
how I do that with friend sub?

10x in advance.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 125 total points
ID: 17074502
--- internal form code ---

private ocxToolbar as control

Public Sub InitToolbar ( c as control )
  set ocxToolbar = c
End Sub

Private Sub Withevents txt_change( ... )
  c.RaiseMyEvent ( ... )
End Sub

--- toolbar control ---

public event SaveLog

private gfrmInternalform as frmInternalform

Private Sub Class_Initialize ()
  set gfrmInternalForm = new frmInternalform
  gfrmInternalForm.initToolbar me
end sub

Friend Sub RaiseMyEvent (...)
  Raisevent SaveLog
End Sub

This should do it...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:avi666
ID: 17079173
few questions.

what is "--- toolbar control ---"? where should I place the code beneth it?
in the usercontrol?

what do I do with ocxToolbar after assigning it with c?
do I need to add class module for it? (Class_Initialize )
if so, who's "Me" in that sub?

also, what is Private Sub Withevents? the compiler bugs me with this declaration...

I'm  a bit clueless...
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17079205
>--- toolbar control ---
should actually read

--- your usercontrol ---


withevents was too much there:
Private Sub txt_change( ... )
  c.RaiseMyEvent ( ... )
End Sub

>gfrmInternalForm.initToolbar me
the ME refers to the usercontrol itself
0
 

Author Comment

by:avi666
ID: 17145355
well, I guess those ideas were good in their ways. I decided to stop messing with it and save the internal form directly from the form.

how easy is that? :)

take the points as a thank for your efforts.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question