views:

37

answers:

1

Hi guys,

I have .NET CF app, with a form that contains a datagrid which I've bound to a BindingList using a solution derived mainly from this article: http://msdn.microsoft.com/en-us/library/aa480736.aspx

I've hooked it up so that when a column header is clicked, I get the HitTest information and check for the Type. If the Type is ColumnHeader, then I initiate a Sort on the underlying BindingList (Using code similar to the example in the link posted above) - which in turn, makes the DataGrid sort itself according to the Property of T that I have clicked. E.g. Description

This works absolutely fine!

The problem comes when I now click around my datagrid - Let's say I have two rows, after the sort is performed, no row is selected. I click a cell in row 1 and I have code that selects the whole row - this operations occurs and all is well. When I now click row 2, row 2 gets selected and all is well, grid still has my sort applied. If I now click row 1 again, my sorting gets reversed, but crucially, the "ApplySort" method is not actually being called. So what is happening? It only happens when I click row 1, the two rows in the grid effectively are reversed. On selecting row 2, it does not occur.

Upon debugging, I can see that mousedown fires (which i have put a return; statement in) and then MouseUp fires, which does the HitTest and calls ApplySort if the columnheader has been clicked, which in this case it has not. I noticed that the change in sort occurs * AFTER * control has left the MouseUp event - so something, somewhere, seems to be altering my grid state after MouseDown/MouseUp have finished.

Any ideas what event/action could be messing with my Grid? I basically want to know if I can suppress anything and everything else once I have called my ApplySort.

A: 

I don't expect many answers to this...but I have just noticed that this behaviour ONLY occurs when the column to sort contains values which are identical to one another.

Columns where the data is different, the behaviour does not occur.

So I suppose this might well be by design - I should make the implementation less generic and sort on a particular id property, which contains distinct values, rather than sort the columns dynamically based on what the user clicked on - as this may well have the side-effect that i've described.

SpaceBison