Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While loading data to combobox show progressbar

Status
Not open for further replies.

HydraNL

Technical User
May 9, 2005
74
NL
Hi, I'm just a junior in VB.NET so please be patient.

I have an AccesDatabase that contains more then 900.000 records. In the Form_Load event these records are loaded into a combobox. This takes about 10 seconds. Sometimes more, sometimes less. To make the waiting for the user less boring I want to show a ProgressBar while loading the data to the Combo. Searched a long time on the internet, but can't find a good tutorial for a beginner anywhere. (not even here) I hope one of you guys could help me out.

The code I use to connect to the database:

Code:
Imports System.Data.OleDb

How do I implement the ProgressBar?

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   Dim ConnectionString As String
   Dim DbConnection As OleDbConnection

   Dim DbCommand As OleDbCommand
   Dim DbDataReader As OleDbDataReader

   Try
      ConnectionString = _
      "Provider = Microsoft.Jet.OLEDB.4.0;" & _
      "Data Source = C:\test.mdb; Mode = Read;" & _
      "Persist Security Info = False"

      DbConnection = New OleDbConnection(ConnectionString)
      DbConnection.Open()

      DbCommandPlaats = New OleDbCommand("SELECT DISTINCT Field1 FROM TABLE", DbConnection)
      DbDataReaderPlaats = DbCommandPlaats.ExecuteReader

      Do While DbDataReaderPlaats.Read
         ComboBox1.Items.Add(DbDataReaderPlaats("PLAATS"))
      Loop

      DbDataReaderPlaats.Close()

How and where do I implement the ProgressBar? Perhaps I need to code another way. I'm not using "Main".
 
You could always get 2005 beta 2: thread796-1057523

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
I have complete code for an independantly threaded process bar (Like the old Netscape Navigator bar, or the 'Knight Rider' effect) that runs in a status bar, but it's a little hefty to put on the forum. I'll see about putting together a demo app and throwing it on my website.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
I remember you posting a screenshot of that Rick - it was a nice effect.

Presumably the user has to have a status bar on the form or can it be used in a progress bar as well?


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
The only reason Hydra cant use a normal progress bar, is that he doesnt know the record count from the datareader.

Since then the thread has moved to slagging off M$ Access


Sweep
...if it works dont mess with it
 
Sorry, I meant could it be used in a progress bar to display the effect that Rick is talking about (like a Knight Rider effect as he describes it!) so there is not concept of how much progress has been made - it's like a simple animation to show them something is happening.

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Presumably the user has to have a status bar on the form or can it be used in a progress bar as well?

It works off of a status bar, It uses a special class that allows you to place complete objects into the panels, and a double buffer graphics class that keeps the painting smooth, then runs the movement code in a seperate thread and refreshes on paint.

Since paint still runs on the parent form's thread, you'll have to be careful with bogging the primary thread. I got on a kick last year about not running any processes in the primary thread. Took a lot of learning and work, but the trade off is that even if a process is incredibly intense, the interface will still respond and refresh correctly.

So I'll throw the status bar and an intence process into the app to give a demo of how the status bar works and how to move processes off of the primary thread. Might have to wait until tonight though, I was out sick yestarday, so I'm still catching up.

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Rick

Does it come with sound effects too?. I can just imagine the joy on Hydra's users faces as they listen to the Knight Rider theme tune, whilst the combo loads up just short of a million items. Ahhhh....sheer bliss!





Sweep
...if it works dont mess with it
 
it goes something like this

swoopswoop swoopswoop these are the voyages of the starship knight rider, his 1à year mission to fin baywatch babes and boldly take of their clothes...

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Thank you gyus for all the effort till now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top