Re: Dropdownlist add handler
Use the 'AddHandler' operator to wire up event handling at run time.
e.g.,
AddHandler someObject.someEvent, AddressOf someMethod
Re: Dropdownlist add handler
SelectedIndexChanged is an included event, no need to write and new one.
Double click on the combo box and it should place you in the code block for the event you mention. Just put your code to update the textbox in that event.
Re: Dropdownlist add handler
The OP's control is dynamically created - that's exactly what 'AddHandler' is for.
Re: Dropdownlist add handler
I guess I missed that part.. carry on :)
Re: Dropdownlist add handler
Quote:
Originally Posted by
David Anton
The OP's control is dynamically created - that's exactly what 'AddHandler' is for.
Hi David.
Actually, I don't agree with using the AddHandler here. Why? Well, why hasn't this dropdownlist control not set up to Inherit from ComboBox? If it is indeed inheriting from CombBox, why re invent the wheel with new handlers and so on. This is exactly why Inheritance exists, so that the child class can make use of the base class' methods and properties. :confused: :)
Re: Dropdownlist add handler
I have not tried this but I thought I would throw it out there.
Have you tried to define the dropdownlist with events? I am thinking that this should give you access to all the events you would have with a drop down list or am I missing something here?
Re: Dropdownlist add handler
What exactly is a dropdown list? Assuming it is some kind of customised ComboBox you should do this:
Code:
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents _dropDownList1 As ComboBox
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
_dropDownList1 = New ComboBox
_dropDownList1.Size = New Size(200, 40)
_dropDownList1.Location = New Point(20, 100)
_dropDownList1.Parent = Me
_dropDownList1.Show()
_dropDownList1.Items.Add("Item1")
_dropDownList1.Items.Add("Item2")
AddHandler _dropDownList1.SelectedIndexChanged, AddressOf _dropDownList1_SelectedIndexChanged
End Sub
Private Sub _dropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' Do something when the selected index changes
End Sub
End Class
Re: Dropdownlist add handler
When you declare an object using WithEvents you do not need AddHandler at all, as the events will alread be "loaded" as well. We have established that. :) The only two options would be to either Inherit from the ComboBox class or using WithEvents.
Re: Dropdownlist add handler
Sorry, you're right. I stand corrected.
Re: Dropdownlist add handler