|
-
Oct 19th, 2008, 12:13 PM
#1
Thread Starter
Lively Member
[RESOLVED] [2005] RevoveHandler Question
I am having a little trouble with event handlers:
I would like to disable (remove) the combobox event handler shown below so that the event will not fire when the value of the combobox is changed programmatically. The event was originally added using AddHandler.
Code:
1 RemoveHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
2 Me.ComboBox1.SelectedValue = ""
3 Me.ComboBox2.SelectedValue = ""
4 Me.ComboBox9.SelectedValue = ""
5 Me.SchoolFilterList.Text = ""
6 AddHandler ComboBox1.SelectedIndexChanged, AddressOf ComboBox1_SelectedIndexChanged
The event for ComboBox1.SelectedIndexChanged still fires when the selected valve for combobox1 is set to “” in line 6. I can not see any code that might be ADDING multiple eventhandlers.
Any thoughts on how to keep the combobox from firing during programatic changes are appricated in advance.
-
Oct 19th, 2008, 12:28 PM
#2
Re: [2005] RevoveHandler Question
declare a form level boolean variable:
vb Code:
dim ignore as boolean = false
check if ignore = true in your ComboBox1_SelectedIndexChanged event and only execute the code if its false. to not execute the code, set ignore = true before changing ComboBox1.SelectedIndex
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 19th, 2008, 12:28 PM
#3
Re: [2005] RevoveHandler Question
Did you add this ComboBox at runtime or in the design-view? I might be wrong on this but, I think that when adding a control at design-time, eventhandlers are automatically added for certain events. So if you're using AddHandler to add another eventhandler at runtime you might end up with multiple eventhandlers even though it wouldnt look like it.
-
Oct 19th, 2008, 01:47 PM
#4
Thread Starter
Lively Member
Re: [2005] RevoveHandler Question
The comboboxes are added at Design time. I commented out the Handles statement and used the AddHandler statement after the form loaded up. For example:
Code:
Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker2.ValueChanged
Becomes
Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles DateTimePicker2.ValueChanged
Then I use:
Code:
AddHandler DateTimePicker2.ValueChanged, AddressOf DateTimePicker2_ValueChanged
My hope was that I could use the RemoveHandler statemen to control the event handling. Is this wrong?
Regardless- I used Paul’s suggestion and it worked fine. Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|