?
Solved

.NET - DataGridView loading with Spinning Progress indicator

Posted on 2011-05-11
5
Medium Priority
?
2,143 Views
Last Modified: 2012-05-11
I have a WinForms program where I would like to show a spinning progress indicator while the DataGridView is loading.  We normally see this in web applications where there is a spinning circle or wheel during a refresh.

I have tried the Circular Progress control in CodeProject:

http://www.codeproject.com/KB/vb/sql2005circularprogress.aspx

Let me know if there is a better control available.

I am invoking a Delegate Function that is getting the data from an SQL server and returning it to the DatGridView while the control is spinning.  This works, but the spinning is jerky rather than smooth.

The basics of the code are below.

Thanks for any suggestions




SpinningProgress1.Visible = True

Dim getinfo As GetTable = AddressOf GetDataTable

DataGridView1.DataSource = getinfo.Invoke(query)

SpinningProgress1.Visible = False

Open in new window

0
Comment
Question by:Tom Sage
  • 3
5 Comments
 
LVL 2

Accepted Solution

by:
roshnipatel earned 2000 total points
ID: 35742718
You might want to invoke the Spinning Progress on a new Thread as well.
Hope this helps:
Option Explicit On


Public Class Main
    
    Delegate Sub SetProgress()
    Delegate Sub SetDataTable(ByVal dt As DataTable)    'pass datatable cross threads


    Private Sub btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn.Click
        Dim doWork As New Thread(New ParameterizedThreadStart(AddressOf MySub))
        doWork.Start(m_parameter)
        MsgBox("Done")
    End Sub

   
    Private Sub btnNoParam_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNoParam.Click
        Dim doWork As Thread
        
        'declare work thread
        doWork = New Thread(New ThreadStart(AddressOf MySub1))
        doWork.IsBackground = True
        doWork.Start() 'Call GenerateFile
   
    End Sub

    

#Region "Methods"
     Public Sub MySub(ByVal m_parameter As String)
	Dim doProgressStart As Thread
        Dim doProgressStop As Thread
        
	'Start Progress Bar
        doProgressStart = New Thread(New ThreadStart(AddressOf ProgressStart))
        doProgressStart.Start()

        'Do Work
	
	'End progress
        doProgressStop = New Thread(New ThreadStart(AddressOf ProgressStop))
        doProgressStop.Start()
    End Sub


    Private Sub MySub1()
        Dim doProgressStart As Thread
        Dim doProgressStop As Thread
        
        'Start Progress Bar
        doProgressStart = New Thread(New ThreadStart(AddressOf ProgressStart))
        doProgressStart.Start()

        'do work
      

      exitSub:
        'End progress
        doProgressStop = New Thread(New ThreadStart(AddressOf ProgressStop))
        doProgressStop.Start()

    End Sub

#End Region


#Region "Progress"

    
    Private Sub ProgressStart()
        If Me.ProgressBar1.InvokeRequired Then
            'use invoke if on a different thread (call from delegate)
            Dim d As New SetProgress(AddressOf StartProgress)
            Me.Invoke(d)
        Else
            'no need for invoke if on the same thread
            StartProgress()
        End If
    End Sub

    Private Sub ProgressStop()
        If Me.ProgressBar1.InvokeRequired Then
            'use invoke if on a different thread (call from delegate)
            Dim d As New SetProgress(AddressOf StopProgress)
            Me.Invoke(d)
        Else
            'no need for invoke if on the same thread
            StopProgress()
        End If
    End Sub
    
    Private Sub StartProgress()
        SpinningProgress1.Visible = True
    End Sub

    Private Sub StopProgress()
        SpinningProgress1.Visible = False
    End Sub

#End Region

    
End Class

Open in new window

0
 

Author Comment

by:Tom Sage
ID: 35743006
Thank you for your response.   I will try it.
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 35744805
Is the grid being loaded in a separate thread?
0
 

Author Comment

by:Tom Sage
ID: 35745943
Yes, doing an Invoke of a Delegate runs on a separate thread.
0
 

Author Closing Comment

by:Tom Sage
ID: 35764252
Thank you for your help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

621 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