I ma using DevExpress controls (which doesnt matter for this example). I have a lookupEdit control and I never want the EditValue_Changed event to fire. Can I use RemoveHandler to do this? If so can someone give me a code example of doing this? Should I put RemoveHandler in the load event of the user control I am creating? Or does it go in the EditValue_Changed event of the lookupControl?
THIS IS A WINDOWS APP NO POSTBACK....Sorry
You can use RemoveHandler from any event you add to an object within one of your own classes. If the event is defined and being handled within a class you do not have access to, you will not be able to remove its handler events.
It would be instructive to learn where this EditValue_Changed event is firing. If it is firing within your application, then you must have wired it up either in the designer or in the code (which means you should be able to call RemoveHandler without difficulty). If this belongs to a 3rd party library and is auto-configured, you may not have this access.
You can't stop the control from firing the postback, but you can just not wire up an event handler to a control's event. You don't need RemoveHandler to do that; just don't attach to the event... But it seem like the issue is the postback, DevExpress should have a feature in there to fire a client-side event, and keep that all on the client and not have to worry about a server-side postback.
If this doesn't help, could you explain more about the problem?
HTH.
You might be able to subclass the control and override the method(s) that trigger the EditValue_Changed event to fire. If you have access to the source code, find where its being called and if that code can be overridden.
Related
I have a usercontrol placed on a form at runtime.
I'm experiencing a UserControl_MouseLeave after FormClosing.
I'm wondering if this should happen under normal circumstances.
To test if this would occur normally as well (and not just in my huge project) I set up a test project with a tiny usercontrol (just having a certain backcolor), and I haven't been able to get the UserControl_MouseLeave event
after receiving the Form_Closing event.
This makes me wonder if my other usercontrol just takes really long to unload therefore doesn't go away right away and thus even stays alive after the FormClosing event.
Unfortunately I did not find any information about when the events can occur.
Does anybody know if this behaviour is normal?
Nothing is destroyed when the FormClosing event is fired so your observation about the disposing taking a long time might actually be correct.
When the form is closed, the WM_CLOSE method is called internally. Here's a flowchart of what happens:
Taken from MSDN article Closing the Window
In WM_CLOSE, the FormClosing event is raised in MDI children and all owned forms. Even after that, there's still a possibility to cancel the operation.
If we continue with the closing, the window is removed from the screen (but it still exists) Only after that, the WM_DESTROY message is sent to both the form itself and the child windows. MSDN states that:
During the processing of the message, it can be assumed that all child windows still exist.
If you have a very complex application that takes longer to dispose of, it's certainly possible that events are still fired after the FormClosing event and even if the form is not visible at that time.
It's also a possibility that there's something wrong with your code but without seeing it, this is what I think is the reason for the behaviour.
Edit: You can take a look at the insides of how the Form handles everything by checking out the Reference Source.
If I close a form in vb.net by using .dispose(), do I need to worry about cleaning up any of the elements that were created inside the form (like addHandler, etc) or does disposal clean up everything for me?
Thanks.
Closing a Form (or calling Dispose() on it) will clean up all of the components within that form. This means that any controls added to the form (or its controls, recursively) will automatically clean up.
Event handlers on controls within the form will get cleaned up.
That being said, this will not clean up event handlers which are subscribing to objects not owned by the form. If you used AddHandler to add an event handler to a type outside of the form, it would be a good practice to use RemoveHandler within an override of Form.Dispose(Boolean) to remove this subscription.
I'm working in a windows application. using VB.NET 1.1
I have an empty form, and I want to generate my design in load session (not in form_load event! but in my form's constructor)
So I know I must generate my components in constructor, but I don't know how to generate button events. I mean I haven't any button in design mode, and these are generating in run-time mode. so how I set button events in this session?
And if you have a better solution for run-time design generation, give it to me. thanks ;)
A few things.
You may add controls at practically any point. It can be in the constructor, the Load, in response to another event, or when a custom method is called.
You can wire up events by using AddHandler myButton.Click, AddressOf Button_Click. You'll have to define the Button_Click event handlder and it will need to have the appropriate signature, which for a button click is (sender as object, e as EventArgs).
When in doubt, temporarily add a real control to you form and go to the hidden designer code (MyForm.vDesigner.vb) and see what is generated as a sample. Copy that code and move it into the main populating code. Then delete the control.
Good luck!
I have a Windows Form that contains a custom control container as a UserControl. For the sake of this question, this custom control container is called Dashboard. This container called Dashboard contains numerous other controls depending on their permissions. I need to raise events that are contained on these controls through the Dashboard control and over to the Windows Form.
How can I bubble up the event? I'm using VB.NET for this project, but can convert C# into VB.NET.
Also, to complicate matters, the main Windows Form is a VB6 project. So, I'm using the InteropFormsToolkit to accomplish this.
I figured it out. I just did what I had said that I wanted to do and created an event with a custom eventargs class and bubbled it up to the VB6 app. Each control needed to implement the custom event such as:
Public Event OnMyCustomEvent(source As Object, e As MyCustomEventArgs)
And continue raising that event up to VB6. In VB6 that event was exposed as a function for me to handle as necessary.
I have a WinForms application with some business objects which implement INotifyPropertyChanged and hook the PropertyChanged event via some controls & BindingSource on the form which raises an event back to my business objects layer...
There's just one issue - everything works fine, except only when the control loses focus. E.G., the user changes some text field, but he has to actually click on some other control somewhere BEFORE he hits the 'save' button (e.g. he has to cause focus on another control).
Is there a way to wire this up to OnClick or something so the change is propogated to my business objects layer as the user types the text (or even after he changed a drop down value) so I don't have to force the user to click on a different text box before he can save?
Googling has lead me nowhere but to examples on how to easily do this in WPF =(. But no WinForms examples...
Please Advise,
Drew
If you are using Binding class to connect object to UserControl, you may try to set binding's DataSourceUpdateMode to OnPropertyChanged.
Please, note that in this way you are writing data to your object before validation. This may be unsuitable for some tasks.