Populating array with color values

R

Roger

Hi,
I'm trying to populate an array with color names. I keep getting an error.
Here is the line that fails:

Dim Colors As String() = Enum.GetValues(enumColor.GetType())
 
K

Ken Cox [Microsoft MVP]

Hi Roger,

You should be able to get all of the colors (including system colors) like
this:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
End If
End Sub 'Page_Load

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub


<form id="Form1" method="post" runat="server">
<P>
<asp:DropDownList id="DropDownList1" runat="server"
AutoPostBack="True"></asp:DropDownList></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>

Ken
MVP [ASP.NET]
 
R

Roger

That worked thanks!


Ken Cox said:
Hi Roger,

You should be able to get all of the colors (including system colors) like
this:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
If Not IsPostBack Then
Dim strSelectedColor As String
Dim enumColor As New KnownColor
Dim Colors As Array = _
[Enum].GetValues(enumColor.GetType())
DropDownList1.DataSource = Colors
DropDownList1.DataBind()
strSelectedColor = DropDownList1.Items(0).Text
End If
End Sub 'Page_Load

Private Sub DropDownList1_SelectedIndexChanged _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Label1.Text = DropDownList1.SelectedItem.Text
End Sub


<form id="Form1" method="post" runat="server">
<P>
<asp:DropDownList id="DropDownList1" runat="server"
AutoPostBack="True"></asp:DropDownList></P>
<P>
<asp:Label id="Label1" runat="server"></asp:Label></P>
</form>

Ken
MVP [ASP.NET]


Roger said:
Hi,
I'm trying to populate an array with color names. I keep getting an
error.
Here is the line that fails:

Dim Colors As String() = Enum.GetValues(enumColor.GetType())
 

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,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top