|
-
Jul 3rd, 2007, 02:59 AM
#1
Thread Starter
New Member
Registry and ComboBox
Hi.
I have a registry path..
HKEY_CURRENT_USER\Software\SilverSky Services\Default\
and I have alot of keys in there.
How do I make the combobox display ALL of the keys at form startup??
-
Jul 3rd, 2007, 03:04 AM
#2
Re: Registry and ComboBox
vb.net Code:
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\SilverSky Services\Default")
Me.ComboBox1.DataSource = key.GetSubKeyNames()
End Using
-
Jul 3rd, 2007, 03:07 AM
#3
Thread Starter
New Member
Re: Registry and ComboBox
Well, that didn't work...
It didn't like Me.ComboBox2.DataSource
I got:
NullReferenceException was unhandled
and the line
"Me.ComboBox2.DataSource = key.GetSubKeyNames()" got yellow...
-
Jul 3rd, 2007, 03:47 AM
#4
Re: Registry and ComboBox
That error means that there is no subkey named "Software\SilverSky Services\Default" under the HKCU hive. As a result the 'key' variable is Nothing so the exception is thrown when you try to call a method on a null reference.
-
Jul 3rd, 2007, 03:50 AM
#5
Thread Starter
New Member
Re: Registry and ComboBox
There is several keys under "Software\SilverSky Services\Default" ..
Type: REG_SZ
..
-
Jul 3rd, 2007, 03:52 AM
#6
Thread Starter
New Member
Re: Registry and ComboBox
Ok.. Now the build started...
Code:
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\SilverSky Services\Remote Desktop\Default")
Me.ComboBox2.DataSource = key.GetSubKeyNames()
End Using
BUT..
There is nothing in that combobox though...
-
Jul 3rd, 2007, 04:03 AM
#7
Re: Registry and ComboBox
Nice to see that you don't get an error when you use the correct path.
Now, if something in the registry is type REG_SZ then it is a VALUE, not a KEY. If you're looking at RegEdit then all the keys are on the left in the tree and all the values are on the right.
If you want to get multiple values froma registry key then you need to call GetValue multiple times, e.g.
vb.net Code:
Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\SilverSky Services\Remote Desktop\Default")
Dim names As String() = key.GetValueNames()
Dim upperBound As Integer = names.GetUpperBound(0)
Dim values(upperBound) As Object
For index As Integer = 0 To upperBound Step 1
values(index) = key.GetValue(names(index))
Next index
Me.ComboBox2.DataSource = values
End Using
-
Jul 3rd, 2007, 04:10 AM
#8
Thread Starter
New Member
Re: Registry and ComboBox
Okay, that worked! Thanks 
Now, another problem..
See post: http://www.vbforums.com/showthread.php?t=476784
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|