$BlogRSDURL$>
This blog will describe some of the learning experiences that I have with .NET, some personal projects that I'm working on, and whatever other topics tickle my fancy.
My Blog LinksSite Links
Currently ReadingBlogroll
Archives
Tools |
Thursday, March 11, 2004ImageListBox Sample
Well, I added to my ImageComboBox sample by extracting some shared drawing and ImageItem collection code, so that it could be used for a ListBox item as well. This allowed me to easily create an ImageListBox.
As I was doing this, I wanted to have the Items collections for these controls be editable at design time, so that users could add an item with an image index at the same time. At first, I tried replacing the Items collection with my own ImageItemList:
For completeness, the ImageItem class looks like the following. It derives from Control so that it can be used in the collection editor. Otherwise, I would need to support a type converter for my class (I may do that in a later sample).
This automatically gave me the collections editor that I wanted during design time with property grid items for ItemData and ImageIndex. However, filling those in didn't actually display the new items. And, worse at run time the control didn't think there were any items in the ListBox. That's because the ListBox.Items property is not virtual and cannot be overridden, so I could only create a new property of the type I wanted. However, the control is still using the underlying Items list and knows nothing about the one I just added. So, I had to go back to the drawing board and came up with a different collection (called BaseImageItemList). This one actually wrapped the ListBox.Items collection and implemented all of the IList methods. The implementation passes through all of the calls to the innerCollection. Then, I added ImageItemList which derived from BaseImageItemList to provide type specific versions of some methods. This allowed me to create a type-specific Items property and still have it work with the items that the base ListBox control was expecting.
This class is actually pretty generic and can be used to wrap any collection with another typed one around it, if you ever find another place where you might need to use that sort of thing. Boy, I can't wait for Generics support in the .NET Framwork! After making those changes, everything worked as expected and I could display items with images that were either added at design or run time. You can download the full sample code from GotDotNet or look at it online and report bugs at the workspace.
Comments:
All Natural Acne Care Skin Treatment - Why It's Far More Beneficial to Your Skin
Post a Comment
All Natural Acne Cure - You Can Cure Your Acne Without Pills & Creams Once You Understand This Aloe Vera Juice Benefits - The Truth About Aloe Vera Juice and Acne Aloe Vera Skin Care - Get Rid of Dark Marks and Acne Scars With Aloe Vera Alternative Acne Medicine Alternative Acne Treatment - Less Painful Route Than Pimple Extraction Alternative Home Treatment For Adult Acne - Cure Your Acne Right Now! An Acne Cure E-Book - What Are the Good E-Books Out There? An Acne Product Review For SensiClear An Acne Treatment Gel - An Overview An Honest Review Of Neutrogena Products For Acne Treatment - Do They Work? Anti Acne & Anti Aging Skin Care Solutions Anti-Aging Acne Skin Care - Start Early for Best Results Anti-aging Moisturizers in the Treatment of Adult Acne Antibiotics Don't Cure Acne - Learn What Really Does Instead! Apple Cider Vinegar Acne Cure Are Birth Control Pills Good For Acne? The Simple Facts Explained About Hormones and Your Skin |