473,411 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Update a textbox ???

Hello

I'm wanting to run through a for loop, and update a text box control to the
value as I loop through, but the only value thats's ever displayed in the
text box is that last value of the counter. Am I missing something???

As I step into the code, I can see the textbox1 test gets update, but I
never see it in the actual text box

private void button1_Click(object sender, EventArgs e)

{

for (int y = 1; y <= 5000; y++)

{

int x = Thread.CurrentThread.GetHashCode();

textBox1.Text = "The number is" + y.ToString();

Thread.Sleep(2000);

}

}
Feb 8 '07 #1
3 19638
Billy Bob wrote:
Hello

I'm wanting to run through a for loop, and update a text box control to the
value as I loop through, but the only value thats's ever displayed in the
text box is that last value of the counter. Am I missing something???

As I step into the code, I can see the textbox1 test gets update, but I
never see it in the actual text box

private void button1_Click(object sender, EventArgs e)

{

for (int y = 1; y <= 5000; y++)

{

int x = Thread.CurrentThread.GetHashCode();

textBox1.Text = "The number is" + y.ToString();

Thread.Sleep(2000);

}

}
That's because you're making the main thread sleep, which means the UI
will not repaint. This isn't ever a good idea. To accomplish your
desired affect, you'll have to run that code in a second thread. Just
don't forget to check the value of InvokeRequired if you hope to update
the UI thread from your second thread.

http://msdn2.microsoft.com/en-us/lib...erequired.aspx

Hope that helps,

--
Sean

website: http://senfo.blogspot.com
Feb 8 '07 #2
It is not even that. The problem is that during the loop the UI thread
doesn't process messages from the message queue because the UI thread is
busy running the loop. If the messages are not processed no painting will be
perfomed. The easiest fix would be to put inside the loop after seting the
Text property the following line of code:

Appliation.DoEvents();
--
HTH
Stoitcho Goutsev (100)

"senfo" <en**********@yahoo.comI-WANT-NO-SPAMwrote in message
news:ew**************@TK2MSFTNGP06.phx.gbl...
Billy Bob wrote:
>Hello

I'm wanting to run through a for loop, and update a text box control to
the value as I loop through, but the only value thats's ever displayed in
the text box is that last value of the counter. Am I missing
something???

As I step into the code, I can see the textbox1 test gets update, but I
never see it in the actual text box

private void button1_Click(object sender, EventArgs e)

{

for (int y = 1; y <= 5000; y++)

{

int x = Thread.CurrentThread.GetHashCode();

textBox1.Text = "The number is" + y.ToString();

Thread.Sleep(2000);

}

}

That's because you're making the main thread sleep, which means the UI
will not repaint. This isn't ever a good idea. To accomplish your
desired affect, you'll have to run that code in a second thread. Just
don't forget to check the value of InvokeRequired if you hope to update
the UI thread from your second thread.

http://msdn2.microsoft.com/en-us/lib...erequired.aspx

Hope that helps,

--
Sean

website: http://senfo.blogspot.com

Feb 8 '07 #3
Thanks for the tip, that works for me.

"Stoitcho Goutsev (100)" <10*@100.comwrote in message
news:O8**************@TK2MSFTNGP06.phx.gbl...
It is not even that. The problem is that during the loop the UI thread
doesn't process messages from the message queue because the UI thread is
busy running the loop. If the messages are not processed no painting will
be perfomed. The easiest fix would be to put inside the loop after seting
the Text property the following line of code:

Appliation.DoEvents();
--
HTH
Stoitcho Goutsev (100)

"senfo" <en**********@yahoo.comI-WANT-NO-SPAMwrote in message
news:ew**************@TK2MSFTNGP06.phx.gbl...
>Billy Bob wrote:
>>Hello

I'm wanting to run through a for loop, and update a text box control to
the value as I loop through, but the only value thats's ever displayed
in the text box is that last value of the counter. Am I missing
something???

As I step into the code, I can see the textbox1 test gets update, but I
never see it in the actual text box

private void button1_Click(object sender, EventArgs e)

{

for (int y = 1; y <= 5000; y++)

{

int x = Thread.CurrentThread.GetHashCode();

textBox1.Text = "The number is" + y.ToString();

Thread.Sleep(2000);

}

}

That's because you're making the main thread sleep, which means the UI
will not repaint. This isn't ever a good idea. To accomplish your
desired affect, you'll have to run that code in a second thread. Just
don't forget to check the value of InvokeRequired if you hope to update
the UI thread from your second thread.

http://msdn2.microsoft.com/en-us/lib...erequired.aspx

Hope that helps,

--
Sean

website: http://senfo.blogspot.com


Feb 8 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sporke13 | last post by:
I have used stored procedures to insert and select but for some reason I can not get this code to update records. Please help I must have made a dumb mistake STORED PROCEDURE CREATE Procedure...
1
by: jijo kuruvila | last post by:
actually my code looks like this private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { DataGrid1.Columns.Visible=true;...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
1
by: mursyidatun ismail | last post by:
Dear all, database use: Ms Access. platform: .Net i'm trying to update a record/records in a table called t_doctors by clicking da edit link provided in the database. when i ran through da...
0
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase...
0
by: sdash | last post by:
I'm working on a simple formview screen that should update a SQL Server 2000 record. I'm sure there must be something simple wrong, but when I press update, the screen refreshes and the changes...
3
by: Antonio | last post by:
Can somebody tell my why the following procedure changes the data in the fields being updated to all the records in the database? private void updateRow(object source,...
5
by: Stephen Plotnick | last post by:
I'm very new to VB.NET 2003 Here is what I have accomplished: MainSelectForm - Selects an item In a public class I pass a DataViewRow to ItemInformation1 Form ItemInformation2 Form
2
by: sirdavethebrave | last post by:
Hi guys - I have written a form, and a stored procedure to update the said form. It really is as simple as that. A user can go into the form, update some fields and hit the update button to...
4
by: justice750 | last post by:
Hi All, I am using a FormView control. The allows me to update records in the database. However, when a database field is null I can not update the field on the form. It works fine when the field...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.