?
Solved

Why textbox  value not showing up immediately?

Posted on 2013-02-06
5
Medium Priority
?
381 Views
Last Modified: 2013-02-21
In my windows application the text box value not getting updated immediately. why ?

When i click the button2 i need to display given information in the text box.
But it is not displaying the value in the text box  instead it's  executing another method (below the text box )
and finally its displaying the value in the text box. Why the assigned values not showing in the text box immediately but it is executing another method ? I need to display the each every action to the user in the text box. How  can i do this ?


 private void button2_Click(object sender, EventArgs e)
        {
           
     
            textBox1.Text +=  Environment.NewLine + formatErrorMessage(" Connecting database....");

            ///getting  the values from db
            ftpValue = FtpValues();
   
                      assignFtpvalues(ftpValue);/// calling this method
         

            textBox1.Text +=  Environment.NewLine + formatErrorMessage(" getting version information ....");

}
0
Comment
Question by:Varshini S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38858576
private void button2_Click(object sender, EventArgs e)
        {
           
     
            textBox1.Text +=  Environment.NewLine + formatErrorMessage(" Connecting database....");


Application.DoEvents();  //Let the interface update by temporarily interrupting the code here

            ///getting  the values from db
            ftpValue = FtpValues();
   
                      assignFtpvalues(ftpValue);/// calling this method
         

            textBox1.Text +=  Environment.NewLine + formatErrorMessage(" getting version information ....");

}
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38858581
Explanation:
When you change the graphical interface the changes are shown only when the application is not busy.
When you execute a piece of code it runs from start to finish UNLESS you interrupt it somehow - the user interface is not updated.  

(The above assumes the code runs in the main thread along with the UI)
0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 38858582
Hi,

You could use a backgroundworker to do the db operation in its DoWork method. Actually it utilises another thread, so you may refresh your UI during its operation.

You may have a look at http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

Giannis
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 38859303
If you're using a loop, then you'd need to call DoEvents() after each update to the TextBox within the loop.

For the BackgroundWorker(), you need to set WorkerReportsProgress() to True, call the ReportProgress() method, and update your TextBox from the ProgressChanged() event.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 38915536
Any reason why my first comment instructing you to use DoEvents was not considered suitable ?
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question