custom control

  • Thread starter Thread starter Nathan Franklin
  • Start date Start date
N

Nathan Franklin

hey guys

I am trying to write a custom control (an editable combobox), doing a lot of
research people have said the best way to do it with a text box overlayed
the combobox..

I have tryed to place this into a custom control which I would like to
reuse..

I cant seem to get the text box onto the control though.. A copy of my code
is below.

On the Me.Controls.Add(Me.txtEditable) line , it throws an argumentexception

Public Class ComboBoxEx

Inherits ComboBox

' controls used

Friend WithEvents txtEditable As TextBox

Sub New()

InitializeComponent()

End Sub

Private Sub InitializeComponent()

txtEditable = New TextBox

' default

txtEditable.MaxLength = 30

txtEditable.Bounds = MyBase.Bounds

txtEditable.Visible = True

txtEditable.BringToFront()

' finally add the textbox control to the design

Me.Controls.Add(Me.txtEditable) ' errors on this line here
'MyBase.Controls.Add(MyBase.txtEditable) ' also if this is uncommented, it
throws the same error

End Sub

Protected Overrides Sub SetItemsCore(ByVal items As
System.Collections.IList)

MyBase.SetItemsCore(items)

End Sub

End Class



If any one could help me out that would be great..

Thanks heaps guys...

Kind Regards
--Nathan
 
Editable combobox is part of CF v2.0 if you can use that.

For v1.0, your could inherit from Control and add to that a combobox and a
textbox etc. As it stands you are inheriting from ComboBox which, as you
found out, doesn't let you add other controls to it. I believe there was a
sample for what you are trying to achieve so search the web/archives (not
100% sure though)

Cheers
Daniel
 
Back
Top