469,609 Members | 1,657 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,609 developers. It's quick & easy.

Statusstrip and StatusLabel

Background:
The Program runs a query on a SQL Database, then it takes the gathered information and outputs it into an excel document and saves it to a specified location.

Problem:
Originally I was using a Label and ProgressBar Located in the form itself but for the sake of appearance I decided it would look better to create a StatusStrip. I relocated the uiFileCreationLabel and uiFileCreationProgressBar to the Status strip as a StatusLabel and ProgressBar. After doing so the ProgressBar worked flawlessly and looked awesome, but the StatusLabel did not follow the ProgressBar's example of good behavior. The code is run inside a Button_Click and the label is supposed to update with the current Percentage of the Overall File Creation. The Only time the label actually updates its text, despite the fact that the code says it should update 4 times for 1 set of files or 6 times for 2 sets of files, is the last time of the updates.

Question:
How can I make the StatusLabel Text update itself? Do I need to call a separate function outside of the Button_Click to update the text specifically?


Expand|Select|Wrap|Line Numbers
  1. Button1_Click(ByVal sender as System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  2. ‘ Declarations and other code
  3.  
  4. ' Progress Bar Initialization
  5. uiFileCreationProgressBar.Maximum = uiDistrictsSelectedListBox.Items.Count * 2
  6.             uiFileCreationProgressBar.Value = dCount
  7.             uiFileCreationLabel.Text = uiFileCreationProgressBar.Value '"Starting File Creation"
  8.  
  9.             Me.UseWaitCursor = True
  10.  
  11.             ' For-loop to Create seperate Query files
  12.             For dCount = 0 To uiDSelectedListBox.Items.Count - 1
  13.                 ' Set file name
  14.                 If (uiUploadTypeComboBox.SelectedIndex = 1) Then
  15.                     fileName = "Custom - " _
  16.                     & Convert.ToString(uiDSelectedListBox.Items.Item(dCount))
  17.                 Else
  18.                     fileName = Convert.ToString(uiDSelectedListBox.Items.Item(dCount))
  19.                 End If
  20.  
  21.                 File1Create(fileLocation, fileName, dCount, connstring)
  22.                 uiFileCreationProgressBar.Value = dCount * 2 + 1
  23.                 uiFileCreationLabel.Text = Convert.ToInt32((((dCount * 2) + 1) / (uiDSelectedListBox.Items.Count * 2)) * 100) & "% Complete"
  24.                 File2Create (fileLocation, fileName, dCount, connstring)
  25.                 uiFileCreationProgressBar.Value = dCount * 2 + 2
  26.                 uiFileCreationLabel.Text = Convert.ToInt32((((dCount * 2) + 2) / (uiDSelectedListBox.Items.Count * 2)) * 100) & "% Complete"
  27.             Next
  28.  
  29.             ' Remove wait cursor
  30.             uiFileCreationLabel.Text = uiFileCreationProgressBar.Value '"100% Completed"
  31.             Me.UseWaitCursor = False
  32.             MsgBox("File(s) Created Succesfully.", 0, "File Creation Status")
  33.             uiFileCreationLabel.Text = uiFileCreationProgressBar.Value '"Press View Report to Begin."
  34.  
  35.  

Comments:
Thank you for any help you have to offer me. If you need any more explanation to help or more code just let me know.
Oct 24 '07 #1
3 4271
Plater
7,872 Expert 4TB
Whenever you want a control to re-draw itself, use the .Update() function on it.

myStatusLAbel.Update() will force the UI to redraw itself.

I didn't look to closely at your code, but this works fairly often to solve that kind of problem.
Oct 24 '07 #2
I ended up figuring it out. I'm not sure if you can update the label itself but what i was able to do is tell the StatusStrip to .Refresh() and that refreshes the label and progress bar.

Thank you for your help though.
Oct 24 '07 #3
Plater
7,872 Expert 4TB
All controls have the .Update(), Refresh() is roughly the same thing though.
Oct 25 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Jim Hubbard | last post: by
2 posts views Thread by robertino | last post: by
1 post views Thread by Carla Simeoni | last post: by
1 post views Thread by S. Viswanathan | last post: by
10 posts views Thread by hzgt9b | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.