Syste.Drawing.Color bound to a dropdown list

Discussion in 'ASP .Net' started by =?Utf-8?B?S2V2aW4gSm9obnNvbg==?=, May 23, 2004.

  1. H

    I have an ASP.NET datagrid written in C#. When editing my datagrid it contains one dropdown list and 4 normal textboxes

    I need the dropdown list to contain all of the colors in the System.Drawing.Color class for selection. I am unsure how to go about this. Could anyone help and provide coded examples

    Any help highly appreciated

    Thank

    Kevin
     
    =?Utf-8?B?S2V2aW4gSm9obnNvbg==?=, May 23, 2004
    #1
    1. Advertisements

  2. Perhaps you could use Reflection to detect all the colors -- since there is
    no collection of colors, and the colors are merely static members of
    System.Drawing.Color class. Here's an example of how to use reflection:

    http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=297

    --
    Manohar Kamath
    Editor, .netWire
    www.dotnetwire.com


    "Kevin Johnson" <> wrote in message
    news:...
    > Hi
    >
    > I have an ASP.NET datagrid written in C#. When editing my datagrid it

    contains one dropdown list and 4 normal textboxes.
    >
    > I need the dropdown list to contain all of the colors in the

    System.Drawing.Color class for selection. I am unsure how to go about this.
    Could anyone help and provide coded examples?
    >
    > Any help highly appreciated.
    >
    > Thanks
    >
    > Kevin
     
    Manohar Kamath [MVP], May 24, 2004
    #2
    1. Advertisements

  3. =?Utf-8?B?S2V2aW4gSm9obnNvbg==?=

    Joe Fallon Guest

    You can add an Enumeration to a cbo or listbox.
    This enumeration lists the known colors in the System.Drawing namespace.
    Public Enum KnownColor

    'air code:
    ==========================================
    'use an Enum in a cbo:
    Dim colorsEnum As Type = GetType(KnownColor)
    Dim mColor As String
    For Each mColor In [Enum].GetNames(colorsEnum)
    Me.cboColors.Items.Add(mColor)
    Next mColor
    ==========================================
    'Use an Enum in a listbox
    Dim colorsEnum As Type = GetType(Colors)
    Dim mColor As String
    Dim alColors As New ArrayList
    For Each mColor In [Enum].GetNames(colorsEnum)
    alColors.Add(New DictionaryEntry(mColor,
    GetEnumDescription(CType([Enum].Parse(GetType(Colors), mColor), Colors))))
    Next mColor

    Me.lstColors.DataSource = alColors
    Me.lstColors.DataTextField = "Value"
    Me.lstColors.DataValueField = "Key"
    ==========================================
    --
    Joe Fallon



    "Kevin Johnson" <> wrote in message
    news:...
    > Hi
    >
    > I have an ASP.NET datagrid written in C#. When editing my datagrid it

    contains one dropdown list and 4 normal textboxes.
    >
    > I need the dropdown list to contain all of the colors in the

    System.Drawing.Color class for selection. I am unsure how to go about this.
    Could anyone help and provide coded examples?
    >
    > Any help highly appreciated.
    >
    > Thanks
    >
    > Kevin
     
    Joe Fallon, May 24, 2004
    #3
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. estafford
    Replies:
    2
    Views:
    2,890
    estafford
    Nov 18, 2004
  2. PJ6
    Replies:
    4
    Views:
    5,126
  3. Victoria Bolton
    Replies:
    0
    Views:
    515
    Victoria Bolton
    May 19, 2006
  4. blouie
    Replies:
    6
    Views:
    424
    blouie
    Mar 29, 2007
  5. Paul
    Replies:
    3
    Views:
    3,064
  6. M. Craig

    How to set background color of List item in dropdown list

    M. Craig, Nov 12, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    433
    M. Craig
    Nov 12, 2003
  7. M. Craig
    Replies:
    1
    Views:
    927
    Victor Garcia Aprea [MVP]
    Jan 9, 2004
  8. Kamaljeet Saini
    Replies:
    0
    Views:
    846
    Kamaljeet Saini
    Feb 13, 2009
Loading...