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??
Printable View
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??
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
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...
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.
There is several keys under "Software\SilverSky Services\Default" ..
Type: REG_SZ
..
Ok.. Now the build started...
BUT..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
There is nothing in that combobox though...
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
Okay, that worked! Thanks ;)
Now, another problem..
See post: http://www.vbforums.com/showthread.php?t=476784