Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / November 2005

Tip: Looking for answers? Try searching our database.

My ComboBoxEx is not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlo - 22 Nov 2005 14:12 GMT
Hello

I'm writing an enhanced version of ComboBox (that inherits from
Windows.Forms.ComboBox) that can display images close to the text.
I've replaced the default Item collection (ComboBox.ObjectCollection, that
is a collecion of Object objects) with my own collection
(ImageComboBoxItemCollection) that holds a number of custom
ImageComboBoxItem items that inherits from Object.

Editor(GetType(ImageComboItemCollectionEditor), GetType(UITypeEditor))> _
Public Shadows ReadOnly Property Items() As ImageComboItemCollection

Everything works fine (serialization included), except for the Overrides of
OnDrawItem that does NOT works. Debugging the ComboBoxEx, I've noted that
OnDrawItem is never called.
If I try to suppress the Shadowing of Items Property, everithing is working
fine again, and OnDrawItem is properly called again.

What's wrong?

Thank you.

Carlo

-------------------------------------------
Carlo, MCP (Windows Based Applications)
carlodevREMOVE@gmail.com
Mick Doherty - 22 Nov 2005 16:12 GMT
Does the example on my site help you out at all?
http://www.dotnetrix.co.uk/combobox.html

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> Hello
>
[quoted text clipped - 23 lines]
> Carlo, MCP (Windows Based Applications)
> carlodevREMOVE@gmail.com
Carlo - 22 Nov 2005 16:26 GMT
At a first look, the answer is 'yes'. I'll study the sample in depth.

The only difference I noted is that you used
Public Shadows ReadOnly Property Items() As ObjectCollection
while I used
Public Shadows ReadOnly Property Items() As ImageComboItemCollection

Do you think that the different type of the collection can be responsible
for the problem I have?

Thany you, Mick, for helping me...

Carlo

-------------------------------------------
Carlo, MCP (Windows Based Applications)
carlodevREMOVE@gmail.com

> Does the example on my site help you out at all?
> http://www.dotnetrix.co.uk/combobox.html
[quoted text clipped - 26 lines]
>> Carlo, MCP (Windows Based Applications)
>> carlodevREMOVE@gmail.com
Mick Doherty - 22 Nov 2005 22:42 GMT
There are two main differences.

The first, as you pointed out, is the collection type. I never managed to
get this working with a custom collection, even when it was inherited from
ObjectCollection, but to be quite honest, I didn't really try too hard as I
believe the simple solutions are often the best.

The second difference is that my custom item is inherited from Component
rather than Object. Inheriting from Object will probably work, but requires
much more work to get the class to Serialize.

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> At a first look, the answer is 'yes'. I'll study the sample in depth.
>
[quoted text clipped - 13 lines]
> Carlo, MCP (Windows Based Applications)
> carlodevREMOVE@gmail.com
Carlo - 23 Nov 2005 08:31 GMT
Good morning Mick

in my previous version, I inherited from Object (and serialization works),
but inheriting from Component is much more useful. For example, the built-in
(name) property does not exist in Object.

However, now I'm trying to "inject" some of your ideas into my version. My
goal is to get a quite more complex Items collection (with ImageIndex,
Image, Tag, Text, ForeColor, etc.).

Is thee only a bit of code that I've not understood.

This is my version:

 Public Property Text() As String
   Get
     Return mText
   End Get
   Set(ByVal Value As String)
     mText = Value
   End Set
 End Property

 Public Overrides Function ToString() As String
   Return Text
 End Function

...and this is your:
 Public Property Item() As Object
   Get
     Return mObject
   End Get
   Set(ByVal Value As Object)
     mObject = Value
   End Set
 End Property

 Public Overrides Function ToString() As String
   If mObject Is Nothing Then
     Return String.Empty
   Else
     Return mObject.ToString
   End If
 End Function

I've not understood the purpose of the Item property. Is is required by the
ObjectCollection to work properly? Do you think can be removed and replaced
with Text?

Thank you once more.

Carlo

-------------------------------------------
Carlo, MCP (Windows Based Applications)
carlodevREMOVE@gmail.com

> There are two main differences.
>
[quoted text clipped - 24 lines]
>> Carlo, MCP (Windows Based Applications)
>> carlodevREMOVE@gmail.com
Mick Doherty - 23 Nov 2005 11:34 GMT
Hi Carlo,

In a standard ComboBox the Item property is declared as Object. At
DesignTime you can only edit the collection to add Strings as the
CollectionEditor is defined as the StringCollection type. At Runtime though,
you can assign any type of Object to the Items collection (such as our
ImageComboItem type) and the DropDown list will display it's ToString value.
To see this in action just change the DrawMode property back to Normal and
you will see that the ComboBox will display the ImageComboItem.ToString()
value for each item.

If you have no intention of assigning complex types to the ImageCombo then
you can safely do away with it and assign the Text property as you've
defined it.

I should also point out a small bug which I have just found. The
SelectedIndexChanged event fires twice and so the OnSelectedIndexChanged()
code should be modified as follows:

Protected Overrides Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
   If Me.SelectedIndex <> currentIndex Then
       currentIndex = Me.SelectedIndex
       MyBase.RefreshItem(Me.SelectedIndex)
   Else
       MyBase.OnSelectedIndexChanged(e)
   End If
End Sub

Signature

Mick Doherty
http://dotnetrix.co.uk/nothing.html

> Good morning Mick
>
[quoted text clipped - 52 lines]
> Carlo, MCP (Windows Based Applications)
> carlodevREMOVE@gmail.com
Carlo - 24 Nov 2005 07:56 GMT
Hello Mick
I need to thank you very much for your valuable help.
Hope to meet you soon in ng!
Sincerely,
Carlo

-------------------------------------------
Carlo, MCP (Windows Based Applications)
carlodevREMOVE@gmail.com

> Hi Carlo,
>
[quoted text clipped - 81 lines]
>> Carlo, MCP (Windows Based Applications)
>> carlodevREMOVE@gmail.com

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.