Iterate through Colors

Posted on 2006-04-13
Last Modified: 2008-02-01

Can someone help me?  What I am trying to do is use a for each loop, to cycle through the System.Darwing.COlor collection, and populate a drop down list with each of there.

thanks in advance

Question by:REA_ANDREW
    LVL 52

    Accepted Solution


                foreach (string s in Enum.GetNames(typeof(System.Drawing.KnownColor)))

    Will give you a list of all known system colors. System.Drawing.Color is a struct rather than an enum, so you can't iterate over it.
    LVL 20

    Author Comment

    Ok I get no errors but the drop down list is empty

     foreach (string s in Enum.GetNames(typeof(KnownColor)))


    LVL 20

    Author Comment

    I have at the top of my C# file

    using System.Darwing;
    using System.Drawing.Imaging;
    LVL 52

    Expert Comment

    by:Carl Tawn
    It should work ok. You don't need .ToString() after s in the Add line, but other than that it should be ok.

    Try stepping through with the debugger and seeing what "s" is during the loop

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    Title # Comments Views Activity
    Problem with C# 1 44
    vb.Net delete files with specific extension 5 37
    Refresh page ASP.NET C# 3 39
    Detect file exist or not 3 38
    Article by: Najam
    Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
    This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now