PRB: Combobox inheritance and Form designer

M

Michael Reimann

Hello

I can't figure out how to make my own Combobox class thru inheritance of a
standard combobox.
At first it seems to work, but then the designer throws exceptions that it's
not able to instanciate my class.
After that it cuts out all code regarding my inherited combobox class.

Does anyone has a working example of an inherited combobox?

With thanks in advance
Michael

p.s: Studio 2003, Framework 1.1
 
Y

Ying-Shen Yu[MSFT]

Hi Michael,
I made a simple combo box derived from the ComboBox class, and it works
fine.
So I think the problem is related to your implementation of the derived
class.
I'd like to know more about your combo box, such as what changes did you
make? When did you get the exception?what is that Exception?
Also You may try my test code(send with the notification mail), and try
adding code on it to see if it works properly.
If you still have problem, please send me a sample to reproduce your
problem,I'll play with the sample and see if I can work out the problem.
If you have anything unclear or any information to update, please be free
to let me know!
Thanks!


Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "Michael Reimann" <[email protected]>
| Subject: PRB: Combobox inheritance and Form designer
| Date: Mon, 13 Oct 2003 21:17:56 +0200
| Lines: 16
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <#[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: dsl-62-220-11-28.berlikomm.net 62.220.11.28
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54348
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| Hello
|
| I can't figure out how to make my own Combobox class thru inheritance of a
| standard combobox.
| At first it seems to work, but then the designer throws exceptions that
it's
| not able to instanciate my class.
| After that it cuts out all code regarding my inherited combobox class.
|
| Does anyone has a working example of an inherited combobox?
|
| With thanks in advance
| Michael
|
| p.s: Studio 2003, Framework 1.1
|
|
|
 
M

Michael Reimann

I was trying different alternatives, but I allways started with a standard
combobox and then I replaced in the designer section the automatically
generated type information by hand. Because the outer class does not change
between the alternatives, it's only shown in the first section.


1) ********

#Const DisableForDesignerMode = True

Public Class MyForm
Inherits System.Windows.Forms.Form

Private Class MyComboBox
Inherits System.Windows.Forms.ComboBox
Public Sub New()
MyBase.New()
DoDirtyThings()
End Sub
#If Not DisableForDesignerMode Then
' Properties
...
#End If
Public Sub DoDirtyThings()
#If Not DisableForDesignerMode Then
' Initialisation
...
#End If
End Sub
End Class

'designer part snip
...
Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
...
Private Sub InitializeComponent()
...
Me.cbMyBox = New MyProject.MyForm.MyComboBox
...
Me.AnyControl.Controls.Add( Me.cbMyBox )
...
End Sub
'end designer part snip
...
End Class


2) ********

Private Class MyComboBox
Inherits System.Windows.Forms.ComboBox
Public Sub New()
MyBase.New()
End Sub
Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub
Protected Overrides Sub SetItemCore(ByVal items As
System.Collection.IList)
MyBase.SetItemCore(items)
End Sub
End Class

'designer part snip
....
Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
....
Private Sub InitializeComponent()
...
Me.cbMyBox = New MyProject.MyForm.MyComboBox
...
Me.AnyControl.Controls.Add( Me.cbMyBox )
...
End Sub
'end designer part snip


3) ********

Private Class MyComboBox
Inherits System.Windows.Forms.ComboBox
Private components As System.ComponentModel.Container = Nothing
Public Sub New(ByVal Container As System.ComponentModel.IContainer)
MyClass.New()
Container.Add(Me)
End Sub
Public Sub New()
MyBase.New()
InitializeComponent()
End Sub
Private Sub InitializeComponent()
components = New System.ComponentModel.Container
End Sub
Protected Overrides Sub RefreshItem(ByVal index As Integer)
MyBase.RefreshItem(index)
End Sub
Protected Overrides Sub SetItemCore(ByVal items As
System.Collection.IList)
MyBase.SetItemCore(items)
End Sub
End Class

'designer part snip
....
Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
....
Private Sub InitializeComponent()
...
Me.cbMyBox = New MyProject.MyForm.MyComboBox(Me.components)
...
Me.AnyControl.Controls.Add( Me.cbMyBox )
...
End Sub
'end designer part snip

************

These different flavours resulted in a quick "research" in the internet and
my hope that one of it will get it working. By the way, without switching to
the designer the code is running.
The error message is in german and says (from my memory) something like:
cbMyBox is not declared or instanciated
failed to create an instance of MyProject+cbMyBox because of an error
happened in MyProject.Global
"Global" is the name of a modul in my Project, but there are no references
to that inside of MyComboBox.
And for now at last ... I'm shure I've forgotten to tell you something.

With best Regards
Michael
 
Y

Ying-Shen Yu[MSFT]

Hi Michael,
How about your problem now?
I have read through the 3 approaches, the latter two seems similiar with
the autogenerated code.
I think they should work. However, the first approach may have a little
defect, if an exception raised in method DoDirtyThings, the instantiation
will fail. If you really need to this, you must be sure that you handled
the exception properly.
If you still have problem on this issue, please send me a small but
complete project to reproduce your problem.I'll work on it to see if I can
find the problem.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "Michael Reimann" <[email protected]>
| References: <#[email protected]>
<[email protected]>
| Subject: Re: PRB: Combobox inheritance and Form designer
| Date: Tue, 14 Oct 2003 11:02:04 +0200
| Lines: 132
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.windowsforms
| NNTP-Posting-Host: dsl-62-220-11-28.berlikomm.net 62.220.11.28
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP09.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms:54375
| X-Tomcat-NG: microsoft.public.dotnet.framework.windowsforms
|
| I was trying different alternatives, but I allways started with a standard
| combobox and then I replaced in the designer section the automatically
| generated type information by hand. Because the outer class does not
change
| between the alternatives, it's only shown in the first section.
|
|
| 1) ********
|
| #Const DisableForDesignerMode = True
|
| Public Class MyForm
| Inherits System.Windows.Forms.Form
|
| Private Class MyComboBox
| Inherits System.Windows.Forms.ComboBox
| Public Sub New()
| MyBase.New()
| DoDirtyThings()
| End Sub
| #If Not DisableForDesignerMode Then
| ' Properties
| ...
| #End If
| Public Sub DoDirtyThings()
| #If Not DisableForDesignerMode Then
| ' Initialisation
| ...
| #End If
| End Sub
| End Class
|
| 'designer part snip
| ...
| Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
| ...
| Private Sub InitializeComponent()
| ...
| Me.cbMyBox = New MyProject.MyForm.MyComboBox
| ...
| Me.AnyControl.Controls.Add( Me.cbMyBox )
| ...
| End Sub
| 'end designer part snip
| ...
| End Class
|
|
| 2) ********
|
| Private Class MyComboBox
| Inherits System.Windows.Forms.ComboBox
| Public Sub New()
| MyBase.New()
| End Sub
| Protected Overrides Sub RefreshItem(ByVal index As Integer)
| MyBase.RefreshItem(index)
| End Sub
| Protected Overrides Sub SetItemCore(ByVal items As
| System.Collection.IList)
| MyBase.SetItemCore(items)
| End Sub
| End Class
|
| 'designer part snip
| ...
| Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
| ...
| Private Sub InitializeComponent()
| ...
| Me.cbMyBox = New MyProject.MyForm.MyComboBox
| ...
| Me.AnyControl.Controls.Add( Me.cbMyBox )
| ...
| End Sub
| 'end designer part snip
|
|
| 3) ********
|
| Private Class MyComboBox
| Inherits System.Windows.Forms.ComboBox
| Private components As System.ComponentModel.Container = Nothing
| Public Sub New(ByVal Container As System.ComponentModel.IContainer)
| MyClass.New()
| Container.Add(Me)
| End Sub
| Public Sub New()
| MyBase.New()
| InitializeComponent()
| End Sub
| Private Sub InitializeComponent()
| components = New System.ComponentModel.Container
| End Sub
| Protected Overrides Sub RefreshItem(ByVal index As Integer)
| MyBase.RefreshItem(index)
| End Sub
| Protected Overrides Sub SetItemCore(ByVal items As
| System.Collection.IList)
| MyBase.SetItemCore(items)
| End Sub
| End Class
|
| 'designer part snip
| ...
| Private WithEvents cbMyBox As MyProject.MyForm.MyComboBox
| ...
| Private Sub InitializeComponent()
| ...
| Me.cbMyBox = New MyProject.MyForm.MyComboBox(Me.components)
| ...
| Me.AnyControl.Controls.Add( Me.cbMyBox )
| ...
| End Sub
| 'end designer part snip
|
| ************
|
| These different flavours resulted in a quick "research" in the internet
and
| my hope that one of it will get it working. By the way, without switching
to
| the designer the code is running.
| The error message is in german and says (from my memory) something like:
| cbMyBox is not declared or instanciated
| failed to create an instance of MyProject+cbMyBox because of an error
| happened in MyProject.Global
| "Global" is the name of a modul in my Project, but there are no references
| to that inside of MyComboBox.
| And for now at last ... I'm shure I've forgotten to tell you something.
|
| With best Regards
| Michael
|
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top