Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why textbox  value not showing up immediately?

Posted on 2013-02-06
5
Medium Priority
?
386 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 45

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 45

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 45

Expert Comment

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

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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