Syste.Drawing.Color bound to a dropdown list

G

Guest

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
 
M

Manohar Kamath [MVP]

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 said:
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?
 
J

Joe Fallon

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 said:
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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top