Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Registry Errors

Registry Errors

Scheduled Pinned Locked Moved C#
csswindows-adminhelpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mikemilano
    wrote on last edited by
    #1

    i am trying to write dg tablestyle grid column widths to the registry: opening and creating keys is just fine, i can open regedit and see the keys. it is when i try to assign a key value to the width of a column that i get the errors. here is how i save the key: Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width); and here is how i am trying to retrieve the key: int ID = Param.GetValue("IHDetailIDWidth"); when i don't run the second line of code, i get no errors, and it is writting to the registry just fine. when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object. it highlights the section of code where i set the value though. any ideas on what i'm doing wrong?

    R 1 Reply Last reply
    0
    • M mikemilano

      i am trying to write dg tablestyle grid column widths to the registry: opening and creating keys is just fine, i can open regedit and see the keys. it is when i try to assign a key value to the width of a column that i get the errors. here is how i save the key: Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width); and here is how i am trying to retrieve the key: int ID = Param.GetValue("IHDetailIDWidth"); when i don't run the second line of code, i get no errors, and it is writting to the registry just fine. when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object. it highlights the section of code where i set the value though. any ideas on what i'm doing wrong?

      R Offline
      R Offline
      Roger Stewart
      wrote on last edited by
      #2

      mikemilano wrote: when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object. Are you creating your Param object before you call the GetValues()method? For example:

      MyAppSettings Param = new MyAppSettings();
      ...
      Param.GetValue("IHDetailIDWidth");
      

      Also, check in your GetValuemethods code to make sure all objects referenced have been created. Roger Stewart "I Owe, I Owe, it's off to work I go..."

      M 1 Reply Last reply
      0
      • R Roger Stewart

        mikemilano wrote: when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object. Are you creating your Param object before you call the GetValues()method? For example:

        MyAppSettings Param = new MyAppSettings();
        ...
        Param.GetValue("IHDetailIDWidth");
        

        Also, check in your GetValuemethods code to make sure all objects referenced have been created. Roger Stewart "I Owe, I Owe, it's off to work I go..."

        M Offline
        M Offline
        mikemilano
        wrote on last edited by
        #3

        i am creating a Param object before i call GetValues() here's a little more of the code with the 2 methods i'm using. I can comment out either one of the 'problem' lines, and the methods work fine, but it is when both are not commented that i get the object error. private void CreateStyles(DataGrid dg) { DataGridTableStyle style = new DataGridTableStyle(); style.MappingName = "IssueHistory"; DataGridTextBoxColumn DetailID = new DataGridTextBoxColumn(); DetailID.MappingName = "DetailID"; DetailID.WidthChanged += new EventHandler(this.SaveIssueGrid); RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software"); RegistryKey SC = softwareKey.OpenSubKey("SC"); if( SC != null) { RegistryKey Param = SC.OpenSubKey("Param"); if(Param != null) { DetailID.Width = (int)Param.GetValue("IHDetailIDWidth",50); // <-- problem line } } // code here to add style to dg } void SaveIssueGrid(object sender, EventArgs e) { RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software",true); RegistryKey SC = softwareKey.CreateSubKey("SC"); RegistryKey Param = SC.CreateSubKey("Param"); Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width); // <- problem line } sorry for the big code post, but i've been working on this for hours with the same results.

        R 1 Reply Last reply
        0
        • M mikemilano

          i am creating a Param object before i call GetValues() here's a little more of the code with the 2 methods i'm using. I can comment out either one of the 'problem' lines, and the methods work fine, but it is when both are not commented that i get the object error. private void CreateStyles(DataGrid dg) { DataGridTableStyle style = new DataGridTableStyle(); style.MappingName = "IssueHistory"; DataGridTextBoxColumn DetailID = new DataGridTextBoxColumn(); DetailID.MappingName = "DetailID"; DetailID.WidthChanged += new EventHandler(this.SaveIssueGrid); RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software"); RegistryKey SC = softwareKey.OpenSubKey("SC"); if( SC != null) { RegistryKey Param = SC.OpenSubKey("Param"); if(Param != null) { DetailID.Width = (int)Param.GetValue("IHDetailIDWidth",50); // <-- problem line } } // code here to add style to dg } void SaveIssueGrid(object sender, EventArgs e) { RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software",true); RegistryKey SC = softwareKey.CreateSubKey("SC"); RegistryKey Param = SC.CreateSubKey("Param"); Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width); // <- problem line } sorry for the big code post, but i've been working on this for hours with the same results.

          R Offline
          R Offline
          Roger Stewart
          wrote on last edited by
          #4

          Sorry for the late reply. Since you know the keys/subkeys that you want to open, try and open/create them all at once. This gets rid of the multiple CreateSubKey/OpenSubKey statements which may be part of the problem. I was able to get a small example working, that I hope will help you. Create a new C# Windows Application and place 2 buttons (btnRead and btnWrite), one label (label1) on the form. Add the Click events for the two buttons using the Designer Property Grid. Replace the generated Click events with the following code:

          		private void btnRead_Click(object sender, System.EventArgs e)
          		{
          			RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param");
          			if ( softwareKey != null )
          			{
          				int x = (int)softwareKey.GetValue("IHDetailIDWidth", 50); // <-- problem line    
          				label1.Text = x.ToString();
          			}  
          		}
          
          		private void btnWrite_Click(object sender, System.EventArgs e)
          		{
          			RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param", true);  
          			softwareKey.SetValue("IHDetailIDWidth",this.Width); // <- problem line
          		}
          

          Roger Stewart "I Owe, I Owe, it's off to work I go..."

          M 1 Reply Last reply
          0
          • R Roger Stewart

            Sorry for the late reply. Since you know the keys/subkeys that you want to open, try and open/create them all at once. This gets rid of the multiple CreateSubKey/OpenSubKey statements which may be part of the problem. I was able to get a small example working, that I hope will help you. Create a new C# Windows Application and place 2 buttons (btnRead and btnWrite), one label (label1) on the form. Add the Click events for the two buttons using the Designer Property Grid. Replace the generated Click events with the following code:

            		private void btnRead_Click(object sender, System.EventArgs e)
            		{
            			RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param");
            			if ( softwareKey != null )
            			{
            				int x = (int)softwareKey.GetValue("IHDetailIDWidth", 50); // <-- problem line    
            				label1.Text = x.ToString();
            			}  
            		}
            
            		private void btnWrite_Click(object sender, System.EventArgs e)
            		{
            			RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param", true);  
            			softwareKey.SetValue("IHDetailIDWidth",this.Width); // <- problem line
            		}
            

            Roger Stewart "I Owe, I Owe, it's off to work I go..."

            M Offline
            M Offline
            mikemilano
            wrote on last edited by
            #5

            thanks for the help .. this has made me realize my problem is in the event handler and not specific to the registry. that is a great shortcut for just opening one key. i wasn't aware you could do it that way. i do appreciate the help, .. i'll start a new thread on the new subject.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups