Results 1 to 8 of 8

Thread: Registry and ComboBox

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Unhappy 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??

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Registry and ComboBox

    vb.net Code:
    1. Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\SilverSky Services\Default")
    2.     Me.ComboBox1.DataSource = key.GetSubKeyNames()
    3. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Re: Registry and ComboBox

    There is several keys under "Software\SilverSky Services\Default" ..
    Type: REG_SZ
    ..

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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...

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Using key As Microsoft.Win32.RegistryKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\SilverSky Services\Remote Desktop\Default")
    2.     Dim names As String() = key.GetValueNames()
    3.     Dim upperBound As Integer = names.GetUpperBound(0)
    4.     Dim values(upperBound) As Object
    5.  
    6.     For index As Integer = 0 To upperBound Step 1
    7.         values(index) = key.GetValue(names(index))
    8.     Next index
    9.  
    10.     Me.ComboBox2.DataSource = values
    11. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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
  •  



Click Here to Expand Forum to Full Width