473,397 Members | 1,961 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,397 software developers and data experts.

listbox

I have a listbox control and I added some colors from which the user can select a color to change the background color of a couple of labels at once
The code I have looks like this
Me.ListBox1.Items.Add("Blue"
Me.ListBox1.Items.Add("White"
Me.ListBox1.Items.Add("Red"

Dim SeeColors = "Color" + "." + ListBox1.SelectedItem.tex

Me.ListBox1.BackColor = SeeColor

Just to try it out I set the background color of the listbox to the selected color

If the user selected red, as far as I know (which obviously is not very far) at this point Me.ListBox1.BackColor is suppose to contain "Color.Red

When I run the program VB.net error message says "the object variable is not set
Any suggestions

Nov 20 '05 #1
5 2077
* "=?Utf-8?B?Qm9iYnkgSg==?=" <an*******@discussions.microsoft.com> scripsit:
I have a listbox control and I added some colors from which the user can select a color to change the background color of a couple of labels at once.
The code I have looks like this:
Me.ListBox1.Items.Add("Blue")
Me.ListBox1.Items.Add("White")
Me.ListBox1.Items.Add("Red")

Dim SeeColors = "Color" + "." + ListBox1.SelectedItem.text

Me.ListBox1.BackColor = SeeColors

Just to try it out I set the background color of the listbox to the selected color


Try: 'Me.ListBox1.BackColor = [Enum].Parse(GetType(KnownColor), ListBox1.SelectedItem)'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #2
* "=?Utf-8?B?Ym9iYnkgag==?=" <an*******@discussions.microsoft.com> scripsit:
"Specified cast is not valid"
Is the error message I now get.


\\\
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.ListBox1.DataSource = [Enum].GetNames(GetType(KnownColor))
End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
Me.ListBox1.BackColor = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(ListBox1.SelectedItem)), KnownColor))
End Sub
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #3
You are Ok
Thanks a bunc
It works
Nov 20 '05 #4
* "=?Utf-8?B?Ym9iYnkgag==?=" <an*******@discussions.microsoft.com> scripsit:
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
HoldColors = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(ListBox1.SelectedItem)), KnownColor))
Me.Refresh()
Dim Appkey As Microsoft.Win32.RegistryKey
Appkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "My App")
Appkey.SetValue("My App", HoldColors)
Pass 'HoldColors.Name' to 'SetValue' instead.
I store the knew color to the registry. But the registry key value now contains: Color [Red]

which generates an error upon restart. For Instance,

Dim key As Microsoft.Win32.RegistryKey
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y App")
Dim name As String = CType(key.GetValue("My App"), String)

HoldColors = name


--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
Help !!!
I use the below code to populate a listbox with all the colors available in vb.ne

[ Dim color As System.Drawing.Colo
For Each color In System.ComponentModel.TypeDescriptor.GetConverter( GetType(Color)).GetStandardValue
Me.ListBox1.Items.Add(color.ToKnownColor
Next
-----------------------------------------------------------------------------------------------------------------------------------------
I use the code below to set the forms background color to the one selected in the listbox and save the color in the registr

[ HoldColors = Color.FromKnownColor(DirectCast([Enum].Parse(GetType(KnownColor), CStr(ListBox1.SelectedItem)), KnownColor)

Me.Refresh(

Dim Appkey As Microsoft.Win32.RegistryKe

Appkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey( "My App"

Appkey.SetValue("My App", HoldColors)

Appkey.Close()

------------------------------------------------------------------------------------------------------------------------
To get the color from the registry I use the code belo

[Dim PanelColors As Microsoft.Win32.RegistryKe
PanelColors = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("M y App"

Dim nameColor As Color = CType(key.GetValue("My App"), Color

HoldColors = nameColor
---------------------------------------------------------------------------------------------------------
The problem is when I pass HoldColors to the registry it shows up in the reg as Color [Red
If I pass HoldColors.Name to the reg. only Red shows u

Either way, when I then try to get the color from the reg. either nothing shows up or I get a vb cras

How do you get Color [Red] or Red converted to Color.Red Help !!!

Nov 20 '05 #6

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

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.