Solved

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

Posted on 2013-05-29
2
433 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 75

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

947 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

22 Experts available now in Live!

Get 1:1 Help Now