Solved

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
WPF - Tooltips for ComboBox items 5 71
.NET tools for adding thread safety to a web app? 3 33
VB.Net Report Printing Issue 3 33
Help with exporting to excel 4 27
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

772 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