Solved

VB.Net - Loop putting Data in a Label or Textbox

Posted on 2013-05-29
2
432 Views
Last Modified: 2013-05-29
Good Day Experts!

I have a longer running Select statement that I display in a DataGridView.  It runs for a "while" so I want to keep the User company by displaying data from each record in a label or textbox on the form.  However, that is not the problem I am faced with.  Issue is I can't get the data to show in the control!  

Here is what I have:

Dim AccountNumber As String = rdrGetAccountNumbers.Item("Account Number")
lblAccountIC.Text = AccountNumber
txtAcctNum.Text = AccountNumber

When stepping through the code and I hover over lblAccountIC.Text  and  txtAcctNum.Text the data is there...it just isn't showing on the screen.  

I am probably totally missing something very simple, but what do you think?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
2 Comments
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 125 total points
ID: 39205265
It's not showing (most likely) because you are running this logic on the main thread of your application...which just happens to be the same thread that all GUI actions occur on. You are basically locking up your GUI until the loop finishes.

As a quick-and-dirty fix, you can add a Applications.DoEvents() call within your loop code.

e.g.

For i As Integer = 0 To SomeUpperBound
    ' Some processing logic

    Application.DoEvents()
Next

Open in new window


This should allow the GUI to update itself while the loop is running. The more preferred way would be to use a BackgroundWorker or a separate thread to run the loop logic, passing message back to the GUI thread that can be used to display on your form.
0
 

Author Comment

by:Jimbo99999
ID: 39205508
That is awesome...I never knew that and it makes sense now.  I will read up on the BackgroundWorker and seperate thread idea.

Thanks for the help,
jimbo99999
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now