Question about inheritance

  • Thread starter Thread starter Tom Rahav
  • Start date Start date
T

Tom Rahav

Hi,

I use VB .NET 2003 and I want to create a new UserControl that will function
as a "smart" combobox that handles few events automatically (such as
auto-complete, etc.) in addition to the regular combobox events.
I created a new class that inherits from: System.Windows.Forms.ComboBox.
I added the some code to the events in the new combobox (in the UserControl
project) and add the control to a win-form in a different project.
The problem is that the enevts I added don't run... When I tried to
understand why, I found that the SmartCombobox control in the win-form
project has its own events (as regular combobox), and what is being run is
the "local" events and not the code I added to the events in the new class.
What should I do in order to run the code in the new control automatically?

Thanks!
Tom.
 
Hi,

I use VB .NET 2003 and I want to create a new UserControl that will function
as a "smart" combobox that handles few events automatically (such as
auto-complete, etc.) in addition to the regular combobox events.
I created a new class that inherits from: System.Windows.Forms.ComboBox.
I added the some code to the events in the new combobox (in the UserControl
project) and add the control to a win-form in a different project.
The problem is that the enevts I added don't run... When I tried to
understand why, I found that the SmartCombobox control in the win-form
project has its own events (as regular combobox), and what is being run is
the "local" events and not the code I added to the events in the new class.
What should I do in order to run the code in the new control automatically?

Thanks!
Tom.

Don't try and capture the events in your subclass, but override the On...
methods.
For example:
Public Class Form1
Private Sub ComboBox1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ComboBox1.Click
MessageBox.Show("Hi!")
End Sub
End Class

Public Class myCombo
Inherits Windows.Forms.ComboBox

Public Sub myCombo()
End Sub

Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
MessageBox.Show("Ho")
MyBase.OnClick(e)
End Sub

End Class

This will display a message box before calling your client app's click
event.

Cheers,
Jason
 
Back
Top