Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

public property

Posted on 2007-08-03
11
Medium Priority
?
167 Views
Last Modified: 2013-12-26
Hi,
i create a textcontrols (combination from label, textbox etc.). I put those controls on a form. When sometthing changed in the textbox the changed event fires. I raise that event from the controls. In the textchanged event a put a variable IsChanged = true. When I stop the form i check the variable IsChanged and if set I can fire a msgbox "save changes?" No problem sofar. When i have 50 textboxes i have to fill every textchanged event.  The question:
Is there a way that when i build something in the textchanged event from the control control that i don't have to fill the 50 events from the controls on the form. Something like a public variable but then more as a "commen property".
thnx
0
Comment
Question by:dgb
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19628449
you could change the events of the textboxes to point to the same event handler...
0
 

Author Comment

by:dgb
ID: 19628518
Hi Angelll
Sounds good, but how can that be done?
regards,
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19628536
generate the handler for 1 text box.
copy the name of that event handler in the event handler name for the other text boxes
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:dgb
ID: 19628767
I'm sorry i don't understand what you mean.
I make a public event in the control. e.g. IsChanged.
When I put the 50 control's on the form I have 50 times that event and have to fill or copy that event. That is not what I meant. When all controls point to the same event then it's ok.
thnx
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 19628791
>When all controls point to the same event then it's ok.
yes, that is what I mean.
when you look in the properties windows, having a control selected, and have the events tab active, you see for which event you have defined an event handler.
you can copy that text, and paste it to the event handler setting of other controls...
0
 

Author Comment

by:dgb
ID: 19628839
Angellll, in your solution i have to copy it 50 times. In case of 50 textboxes.

When you see it as a public variable. I put in my own build control in the event "textchanged" the variable bIsChanged = true. When the textbox is changed this variable is set. In that case i don't have to copy anything. When i leave the form i only have to find out if bIsChanged is true or false. This is working but I don't like public variable's
thnx
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 19629471
Make your "IsChanged" a SHARED variable...then it will be common to all the Controls.
0
 

Author Comment

by:dgb
ID: 19630953
Hi, i think this is not working. When you share the variable, the controls on an other forms are also "included". If you make a change there it has also influence in the original screen.

0
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 19631192
I might be missing something here but this looks very like the classic "IsFormDirty" issue.  And the classic solution to that is a _form_ level variable (so we're not talking about a public variable, unless you want it to be, or about changes on one form impacting on another) declared, say, "Private FormDirty As Boolean = False", an event_handler that sets it, for example

    Private sub MyControlChanged(<appropriate arguments>)
        If <sender>.IsChanged Then FormDirty = True
    End Sub

and code on startup to add that event handler to all the relevant types of controls on the form

    For Each ctl As Control In Me.Controls
        If TypeOf(ctl) Is MyControl Then
            mctl = CType(ctl,MyControl)
            AddHandler mctl.IsChanged, AddressOf MyControlChanged
        End If
    Next

remembering the need to use that recursively if the controls are nested inside other controls: panels, groupboxes, whatever.

Or is that not what you want to achieve?

Roger
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 19631452
Ah...gotcha...the dialog so far sounded like all the controls in question were on the same form.

I think Roger is on the right track here.  "Wire up" all the event handlers to the same sub.

This is essentially what angelII suggested...but Roger has done it via code at run-time instead of at design-time.
0
 

Author Comment

by:dgb
ID: 19631867
Roger is right. The idea is that when there is a change in one of the input fields the vatiable formdirty is set. I wil try if I get it running.
Thnx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

572 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