DataGrid sorting not throwing event

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carl Dreher

    #1

    DataGrid sorting not throwing event

    I need to detect when the user clicks on a column header to resort the data
    in a DataGrid. I've added an event handler to my class, which is a form that
    hold the DataGrid:

    Private Sub DataGridLamps_N avigate(ByVal sender As System.Object, ByVal ne
    As System.Windows. Forms.NavigateE ventArgs) Handles MyDataGrid.Navi gate
    'do stuff here
    End Sub

    The form also has:
    Friend WithEvents MyDataGrid As System.Windows. Forms.DataGrid

    The handler is never called even though clicking on the grid headings
    resorts the data.

    Also (perhaps related), if I use Form Designer to set
    MyDataGrid.Allo wingSorting = false, the Grid ignores this an happily allows
    sorting.

    Is this a known bug? We're using Visual Studio 2003 V7.1.3008, and .Net
    V1.1.4322

  • Carl Dreher

    #2
    Found solution

    The navigation event seems to be totally broken but I did find a work-around.

    1. When ever the user clicks on a DataGrid heading, causing the colums to
    re-sort, the DataGrid.Click event fires. (Note that this event does not fire
    when you click on a cell or on a row header on the left side of the
    DataGrid.) So, first you must catch it and set a flag indicating that the
    heading was clicked.

    Note that this happens BEFORE the resorting occurs, so you can't at this
    point read the grid and know where the new cells are because they haven't
    moved yet.

    2. After the columns are resorted, the DataGrid.Layout event fires. The
    solution is to also catch this event (which will happen a lot when the grid
    is first drawn) and check if your flag was set. If so, you know that the
    grid is resroted as a result of the header being clicked. So clear the flag
    and then do whatever you originally wanted to do with the broken
    DataGrid.Naviga tion event.

    Comment

    Working...