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(o bject sender, EventArgs e)
{
for (int y = 1; y <= 5000; y++)
{
int x = Thread.CurrentT hread.GetHashCo de();
textBox1.Text = "The number is" + y.ToString();
Thread.Sleep(20 00);
}
} 3 19656
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(o bject sender, EventArgs e)
{
for (int y = 1; y <= 5000; y++)
{
int x = Thread.CurrentT hread.GetHashCo de();
textBox1.Text = "The number is" + y.ToString();
Thread.Sleep(20 00);
}
}
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
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.DoEv ents();
--
HTH
Stoitcho Goutsev (100)
"senfo" <en**********@y ahoo.comI-WANT-NO-SPAMwrote in message
news:ew******** ******@TK2MSFTN GP06.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(o bject sender, EventArgs e)
{
for (int y = 1; y <= 5000; y++)
{
int x = Thread.CurrentT hread.GetHashCo de();
textBox1.Text = "The number is" + y.ToString();
Thread.Sleep(20 00);
}
}
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
Thanks for the tip, that works for me.
"Stoitcho Goutsev (100)" <10*@100.comwro te in message
news:O8******** ******@TK2MSFTN GP06.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.DoEv ents();
--
HTH
Stoitcho Goutsev (100)
"senfo" <en**********@y ahoo.comI-WANT-NO-SPAMwrote in message
news:ew******** ******@TK2MSFTN GP06.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(o bject sender, EventArgs e)
{
for (int y = 1; y <= 5000; y++)
{
int x = Thread.CurrentT hread.GetHashCo de();
textBox1.Text = "The number is" + y.ToString();
Thread.Sleep(20 00);
}
}
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 OrdersAddDetail
( @fname nvarchar(50),
@lnametxt nvarchar(50),
@add1 nvarchar(50),
@add2 nvarchar(50),
|
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;
DataGrid1.Columns.Visible=true;
TextBox t1=new TextBox();
TextBox t6=new TextBox();
TextBox t7=new TextBox();
|
by: Neo Geshel |
last post by:
This works:
<form>
<asp:TextBox id="name" />
<%= name.ClientID %>
</form>
But this DOES NOT work:
<form>
|
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 browsers and click update it gave me this error:
Specified argument was out of the range of valid values. Parameter name:
|
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 .NET 2.0
DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be
used in the ProviderName property of a SQLDataSource and loads properly
at run time.
The application I'm writing is a bit more complex than the example I'm
about to...
| |
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 are not committed to the table.
Can anyone give me some suggestions here?
Thanks in advance (code below)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditItem.aspx.cs"
Inherits="EditItem" %>
|
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,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
SqlConnection conn = new SqlConnection
(ConfigurationSettings.AppSettings);
SqlCommand updCommand = new SqlCommand();
|
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
|
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 update the information which is stored in a SQL database.
In testing we noticed that the form was updating correctly but the update mechanism was also updating the first record of the table in the sql database every time. No error messages are on...
|
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 is not a null value. I am not using any code behind (C#) to bind the data or manipulate the data.
I have read that when there is a null value in the database that there is no record in the "dataset". Can anyone show me how to bind a value in the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |