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 / WinForm Controls / January 2006

Tip: Looking for answers? Try searching our database.

Deriving from ComboBox and creating a new Items

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joe - 26 Jan 2006 16:01 GMT
I want to create a new Items class for my ComboBox but the problem is the
Items doesn't get stored at design time and at runtime,
OnDrawItemEventArgs.Index always = -1.

I can check the Items collection and verify that the items were added at
runtime. Should I be overriding a different Method in this case?

-Joe
"Jeffrey Tan[MSFT]" - 27 Jan 2006 06:08 GMT
Hi Joe,

Thanks for your post.

I am not sure I understand your problem context very well. Can you give a
more clear description regarding it?

Do you create a customized combobox inherited from the standard ComboBox?

I look forward to hearing from you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Joe - 27 Jan 2006 07:04 GMT
Yes, I created a control which inherits from ComboBox.
public class MyComboBox : ComboBox
{
...
   new public AClass Items
   {
       get
           {
               return m_aclass;
           }
   }
...
}

I also override OnDrawItem. The problem is OnDrawItemEventArgs.Index always
= -1. In addition, at design time if I click the Items property, a dialog
comes up allowing me to add new items to my collection. I can add as many as
I want to. If I click Ok (to close the dialog) and then click the Items
property again the items I added are there. Once I run the application, the
items are no longer there. If I recheck at design time again by clicking the
Items property, the items are gone.

So I actually have 2 problems.

AClass inherits from CollectionBase.

I hope this is a little more clear.

-Joe

> Hi Joe,
>
[quoted text clipped - 12 lines]
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
"Jeffrey Tan[MSFT]" - 27 Jan 2006 08:53 GMT
Hi Itzik ,

Thanks for your feedback.

#1, No, your code simply uses a new Items property to hide the standard
ComboBox Items property. However, the combobox does not know to use this
new Items property to render its content. The standard Items property is of
type Object collection, why you can not use the existing Items property? If
you really want to hide it, you have to loop through your m_aclass
collection  and add each item to base.Items property.

#2, please refer to the link below:
"56.11 How can I persist a collection of items into code?"
http://64.78.52.104/FAQ/WinForms/FAQ_c81c.asp#q713q

Hope this helps

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Signature

Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


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.