By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Swapping out a color programmatically

P: n/a
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?

Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
This should help

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

Peter

"BobAchgill" <an*******@discussions.microsoft.com> wrote in message
news:0d****************************@phx.gbl...
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?

Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.