Friday, March 16, 2012

Populating array with color values

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())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" <TheFlash@.Superhero.com> wrote in message
news:uguKrq64DHA.2412@.TK2MSFTNGP11.phx.gbl...
> 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())
That worked thanks!

"Ken Cox [Microsoft MVP]" <BANSPAMken_cox@.sympatico.ca> wrote in message
news:%236cfSE74DHA.1804@.TK2MSFTNGP12.phx.gbl...
> 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" <TheFlash@.Superhero.com> wrote in message
> news:uguKrq64DHA.2412@.TK2MSFTNGP11.phx.gbl...
> > 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())

0 comments:

Post a Comment