Swapping out a color programmatically

B

BobAchgill

When I try to change the Color.Lime with a string that
contains the contents "Color.Lime" I get a Casting
compile error. So how can I get past this casting issue
to change out the color programmatically?


This is the line of code without trying to change color
programmatically (no problem):


Dim LVI As New ListViewItem(New String() {myDataRow
("Id").ToString(), myDataRow("fName"), myDataRow
("lName")}, -1, Color.Empty, Color.Lime, Nothing)


Thes are the lines of code when I try to change the color
programmatically:


Dim strRowColor As Object = "Color.Lime"

Dim LVI As New ListViewItem(New String() {myDataRow
("Id").ToString(), myDataRow("fName"), myDataRow
("lName")}, -1, Color.Empty, strRowColor, Nothing)


This is the error message that I get trying to change the
color using a variable to substitute the color on the run:

"Specified cast is not valid"

What will work here to accomplish changing the color?
 
P

Peter Proost

This should help

Dim strColor As String = "White"
TextBox1.ForeColor = Color.FromName(strColor)

Peter
 

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

Top