DataGrid sorting not throwing event

G

Guest

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_Navigate(ByVal sender As System.Object, ByVal ne
As System.Windows.Forms.NavigateEventArgs) Handles MyDataGrid.Navigate
'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.AllowingSorting = 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
 
G

Guest

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.Navigation event.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top