Getting the Onsorted event in a datgridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spinnersean
    New Member
    • Aug 2008
    • 3

    Getting the Onsorted event in a datgridview

    Hi all,

    I am trying to detect when the onsorted event fires in a datagridview.

    I want to freeze the screen on ColumnHeaderMou seClick (That's OK) and unfreeze after the sort.

    (That's not OK)


    CODE:
    Code:
        Private Sub dgv_ColumnHeaderMouseClick _ 
    (ByVal sender As System.Object, ByVal e As  _ System.Windows.Forms.DataGridViewCellMouseEventArgs) _ 
    Handles dgv.ColumnHeaderMouseClick 
    
            LockWindowUpdate(Me.Handle.ToInt32)
    
        End Sub
    The code above works fine and to call the onsorted event I am using

    CODE:
    Code:
       Public Sub dgvLabProcesses_Sorted _ 
    (ByVal sender As System.Object, ByVal e As System.EventArgs) _ 
     Handles dgvLabProcesses.Sorted
            LockWindowUpdate(0)
        End Sub
    Anyone know why this is not happening? Is blocking the screen update preventing sorting?


    Many Thanks

    SS
    Last edited by Frinavale; Jan 20 '09, 03:43 PM. Reason: added [code] tags
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    I would say that yes LockWindowUpdat e() is blocking the updates, as that is what it is designed to do.
    If you are just trying to keep people from interacting with the form while the sorting is going on, their are other options you can take.
    I throw up a "splash screen" of sorts that says what is going on, and hide it when done with the sorting.
    You could also set the Enabled property to false on the form (which would disable it along with the child controls) and then set it to true again.
    You could mark all the controls as hidden and then make them visible again when you are done too.

    Be aware that not all column types are considered sortable and thus will never fire the Sorted event.

    Comment

    • Spinnersean
      New Member
      • Aug 2008
      • 3

      #3
      Hi all,

      Thanks Plater for clarifying that. rather than use a splash screen I am going to hide and show the datagridview.

      Code:
          Private Sub dgv_ColumnHeaderMouseClick _ 
      (ByVal sender As System.Object, _ 
       ByVal e As System.Windows.Forms. _ 
      DataGridViewCellMouseEventArgs) 
              dgv.Visible = False
              Formatting()
          End Sub
      And then in the formatting subroutine dgv.visble = true.


      thanks all
      Last edited by Spinnersean; Jan 20 '09, 04:19 PM. Reason: Thanks frinavale of code tags

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Just a suggestion:

        It's a good idea to at least show a message that you are doing something when you hide the GridView or else your end users will be left wondering what happened to it.

        When you hide the GridView, add a label in it's place saying "Sorting... ." or something.

        This will inform the end user that something is happening so that they aren't worried the application has crashed or is doing something "weird". This is why Plater suggested a splash screen.

        -Frinny

        Comment

        • Spinnersean
          New Member
          • Aug 2008
          • 3

          #5
          Thanks frinavale that is a good idea so I will put a label with 'Loading...' under the dgv.

          Comment

          Working...