Results 1 to 8 of 8

Thread: [1.0/1.1] Updates control values

  1. #1

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Smile [1.0/1.1] Updates control values

    Hi all,

    I have a form with several text boxes. On the form load I read the registry and load some data(text) to those text boxes. It's fine.

    Also use two buttons to backup the registry and restore the registry. That step also working fine on my application.

    On the first installation of my application, there is no any entry on the registry. So user can restore previously backup registry. It's update the registry perfectly. But it not update values to text boxes. I have to close and open again the form. At that time I can see all values correctly.

    I try to do the same thing as form load, get the values from the registry. But it freeze the form.

    So, how can I dynamically load those values. Exiting and opening the form again is not a user friendly at all.

    I'm waiting for your comments.

    Thanks
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

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

    Re: [1.0/1.1] Updates control values

    What can we tell you from that? Plain and simple, there's no reason that you should not be able to get the appropriate values from the Registry and display them in the TextBoxes any time you like, assuming that you're executing the appropriate code. Therefore you must not be executing the appropriate code. As we haven't seen the code you are executing, there's no way for us to say what's wrong with it.
    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
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [1.0/1.1] Updates control values

    Ok, here is the code how I restore the registry settings.

    Code:
    		private void btnRestore_Click(object sender, System.EventArgs e)
    		{
    			if(File.Exists("c:\\cfg.bk"))
    			{
    				ProcessStartInfo regImport = new ProcessStartInfo( "regedit.exe" );
    				regImport.UseShellExecute = true;
    				regImport.Arguments = "/s c:\\cfg.bk";
    				System.Diagnostics.Process.Start( regImport );
    			}
    			else
    			{
    				MessageBox.Show("Restore Failed. Please use manual setup.", "Error", 
    					MessageBoxButtons.OK, MessageBoxIcon.Error);
    			}
    			//textServer.Text = "sample text";
    			textServer.Text = regKey.GetValue("server", "192.168.2.17\\SQL2005").ToString();
    		}
    Actually this restore button is on one tab page, and all other controls in another tab page.

    If I use the code line which is commented, after changing the tab text is displayed. But when I get the text from the registry it don't happened.

    Do the same thing as,

    Code:
    textServer.Text = regKey.GetValue("server", "192.168.2.17\\SQL2005").ToString();
    in form load as well. In form load it works.

    So, why is that happened, and how?
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

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

    Re: [1.0/1.1] Updates control values

    I'm guessing that your regKey is no longer valid after you restore the Registry. You probably have to reopen the key.

    It's also a possibility that it won't work because the restore operation is in progress. You might try calling WaitForExit on your Process before trying to get a value to confirm that.

    You see how much information we get when you provide your code? Just because you know what you're doing doesn't mean we do with a few words of explanation. The same thing can usually be done with infinite variations so we need to know EXACTLY what you're doing to know exactly what the issue might be.
    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
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [1.0/1.1] Updates control values

    Quote Originally Posted by jmcilhinney
    It's also a possibility that it won't work because the restore operation is in progress. You might try calling WaitForExit on your Process before trying to get a value to confirm that.
    Yes pal, this is the issue. Before the completed the restore process, try to set text. At that time text not exit. I try it on debug, works. Because the delay is enough to complete the process.


    Quote Originally Posted by jmcilhinney
    You see how much information we get when you provide your code? Just because you know what you're doing doesn't mean we do with a few words of explanation. The same thing can usually be done with infinite variations so we need to know EXACTLY what you're doing to know exactly what the issue might be.
    Yes. I don't want to do it next time.
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

  6. #6

    Thread Starter
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [1.0/1.1] Updates control values

    I have one thing to know.

    Say I use a delay to set the data in text boxes, after starting the process. I think quite same scenario take place on WaitForExit.

    So is there any major advantage/disadvantage?
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

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

    Re: [1.0/1.1] Updates control values

    The point of WaitForExit is that your code will wait as long as it needs to to ensure that the process has exited and no more. If you use some sort of arbitrary delay then you cannot guarantee that you will wait long enough and you may also wait longer than is necessary. WaitForExit is the best, and "proper", way to do it.
    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
    PowerPoster eranga262154's Avatar
    Join Date
    Jun 2006
    Posts
    2,201

    Re: [1.0/1.1] Updates control values

    I got the point pal. Thanks
    “victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha

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