473,320 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Got a nagging listbox questions

I have tried everything I know, looked every where, and I still cannot figure out this
You see, I have a color stored in the registry and it shows up as say Color [red
and I cannot get that color out as Color.Red so that I can put it in a variable to be assigned to a label.backcolo
The registry getvalue code I use is as folllows

-----------------------------------------------------------------------------
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y App"

Dim nameColor = PanelColors.GetValue("My App"

Label1.BackColor= nameColo
-----------------------------------------------------------------------------------------
I get an error message saying "Specified cast is not valid"
Nov 20 '05 #1
4 1007
"bobby j" <an*******@discussions.microsoft.com> schrieb
I have tried everything I know, looked every where, and I still
cannot figure out this: You see, I have a color stored in the
registry and it shows up as say Color [red] and I cannot get that
color out as Color.Red so that I can put it in a variable to be
assigned to a label.backcolor The registry getvalue code I use is as
folllows:

-------------------------------------------------------------------------- ---- PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y
App")

Dim nameColor = PanelColors.GetValue("My App")

Label1.BackColor= nameColor
You should enable Option Strict first.
- The variable type is missing
- The type cast is missing
- You are trying to assign a String to a property expecting a Color object
-------------------------------------------------------------------------- ---------------- I get an error message saying "Specified cast is not valid"

You are storing the wrong string. The string is not parsable. You could use
System.Drawing.Color.ToKnownColor.ToString to convert a color object to a
string to store it in the registry, then use System.Drawing.Color.FromName
to convert it back from String to a Color object. Example:

Dim s As String
s = Color.Red.ToKnownColor.ToString
MsgBox(s)

s = "Blue"
Me.BackColor = Color.FromName(s)

--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
* "=?Utf-8?B?Ym9iYnkgag==?=" <an*******@discussions.microsoft.com> scripsit:
I have tried everything I know, looked every where, and I still cannot figure out this:
You see, I have a color stored in the registry and it shows up as say Color [red]
and I cannot get that color out as Color.Red so that I can put it in a variable to be assigned to a label.backcolor
The registry getvalue code I use is as folllows:

------------------------------------------------------------------------------
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y App")

Dim nameColor = PanelColors.GetValue("My App")

Label1.BackColor= nameColor
------------------------------------------------------------------------------------------
I get an error message saying "Specified cast is not valid"


I remember there was a similar topic some days ago:

\\\
Dim ColorName As String = ...
Me.Label1.BackColor = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), ColorName), KnownColor))
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
Thank you guys
The both of you contributed to the solution
Armin, for his conversation
and Herfried, for his suggestion to pass HoldColor.Name instead of just HoldColor (from the previous post)
Once again, Thanks
I sure learned a lot

Nov 20 '05 #4
It's always a good idea to store colors as an RGB or ARGB value instead of
an actual name

"bobby j" <an*******@discussions.microsoft.com> wrote in message
news:89**********************************@microsof t.com...
I have tried everything I know, looked every where, and I still cannot figure out this: You see, I have a color stored in the registry and it shows up as say Color [red] and I cannot get that color out as Color.Red so that I can put it in a variable to be assigned to a label.backcolor The registry getvalue code I use is as folllows:

-------------------------------------------------------------------------- ---- PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y App")

Dim nameColor = PanelColors.GetValue("My App")

Label1.BackColor= nameColor
-------------------------------------------------------------------------- ---------------- I get an error message saying "Specified cast is not valid"

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: wallacej | last post by:
I am trying to retrieve a selected value from a listbox and store it in a string (char) variable. I am using the following code: calibIndex=SendMessage(hWnd,(UINT)IDC_LIST_CALIBOPTS,(WPARAM)0,...
4
by: questions | last post by:
I create a Form and call another class (e.g. class1.cs). (class1.cs) contains a command to call back the Form to display a string variable in a listbox. However, it doesn't works. The listbox gets...
3
by: Reb | last post by:
Hi, I am using drop down menu in my pages. In one of my page,there is a listbox control below the menu. This listbox control is hiding the drop down menu items. How can i make the drop down...
8
by: Steve Schroeder | last post by:
For some reason I cannot get the OnSelectedIndexChanged event to fire for a listbox I have on a page. I'm able to populate the listbox with data from a stored procedure, but cannot trigger the...
4
by: Mike Parris | last post by:
I want to represent a list of items as a heirarchy by, indenting each item by a set amount depending on its level. For example level 1 = no spaces, level 1 = 2 spaces etc. If I try too use...
3
by: George | last post by:
Sub ExcelToListBox() Dim xRange As Object Dim ary Dim xValue As String xRange = oXL.Range("A1:A9") 'has letters A-H ary = xRange.value xValue = ary(3, 1) 'xValue = C...
1
by: Spock | last post by:
Hi. I have a form with a listbox and a few label fields all bound to a dataset. When i navigate the listbox the labels change accordingly. so far everything works good. I made a button to...
0
by: John Dann | last post by:
I had a listbox that allows reordering of listed items using the mouse to drag and drop. In the DragDrop event handler, the key instructions are: MyListBox..Items.RemoveAt(PreMoveIndex)...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
1
by: John | last post by:
Hi I have a few questions regarding Listbox; 1. How can I fill Listbox from an access table with multiple columns? 2. How can I return the user selected (highlighted) items in a Listbox...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.