Incorrect items selected when filtering.

Jan 20, 2014 at 3:56 PM
I posted an issue to the issues section regarding this that also includes source code and how to recreate the issue using the posted code.

Basically, if items are in the grid that contain identical fields or are extremely similar and one uses a filter, items in the list are incorrectly selected. However, selecting these same items before applying a filter works properly - once the filter is applied and the grid gets into this state, then it seems that it takes a restart of the application to get the grid to work properly again.

Thanks.
Coordinator
Jan 20, 2014 at 4:36 PM
Working on it
Coordinator
Jan 20, 2014 at 5:01 PM
Remove override Equals from Output class.
See issue link for for more details.

Regards,
bpoojary
Jan 20, 2014 at 7:19 PM
Edited Jan 20, 2014 at 7:20 PM
Please see my comments in the issue link. The overridden equals operator follows Microsoft guidelines. The Equals function checks objects for Value equality. However, in the grid, it would seem that, assuming it is possible, there needs to be a check for reference equality. If there is a way to check for reference equality between what is clicked on and what is selected, the scenario should work.
Jan 20, 2014 at 9:27 PM
Edited Jan 20, 2014 at 10:41 PM
I'm working on this. I will post code when I get a finished solution. The solution I posted was incomplete.
Jan 21, 2014 at 1:12 AM
I added another element to the Equals override that checks another field. In general, there will be no two Output objects within a parent that have the same content and names, so the field that I added is the Parent field. I really do not think that this is the correct way to do this - but it works and my project is only an internal tool at this point. Other developers may not be able to add such an element to the value equality check and, therefore, this may come up again from someone else.

I still think this can be done in the control by using item indexes with the backing controls. I got the items to select properly, however, on deselecting an item, the item was not being removed from the SelectedItems property (even though I called "RemoveAt" with the index of the item) in the MultiSelector control for some reason - perhaps because elsewhere it was trying to remove it by calling .Equals instead of trying to remove it by reference - which should always work. Since the item was in the SelectedItems property subsequent adds failed as the control code is structured in such a way as to look for the item in SelectedItems and then assume that the user wants to remove it if it is there. I do not have the patience to walk this all the way through at this point.

Making "==" return value equality and not overriding Equals is inconsistent with Microsoft practices, and, IMHO, should never be done as it is entirely possible that some other framework element would produce bad results because of this. If the only control in the project is the Extended Grid, then fine, but with other framework controls in the project, IMHO, doing that would be asking for trouble. Equals is the only function that should return value equality. This is at least implied in the link that I posted to the Microsoft guidelines on overriding Equals and "==" - "==" is explicitly stated to be used for reference equality such as that obtained from object.ReferenceEquals.
Coordinator
Jan 21, 2014 at 2:39 AM

I agree with your point.
I was too shocked to see it behave like that.
Can report problem to Microsoft as well.
I need to find optimum fix for this.

Jan 21, 2014 at 3:36 AM
When I get back to work tomorrow, I will take another look at this to see if I can trace it to find out what is causing the item to not be removed from the MultiSelector.SelectedItems property. If I cannot figure it out in a reasonable time, I'll upload the code that I have. It is all centralized in DataGrid.cs- that code, I am assuming, was written by MS.

As far as I have taken it, I have been able to get it to work by ensuring that the reference of the found item is the same as the item that was clicked on as the "selection target." The changes so far are not extensive - rather just tweaks to small parts of the code. I'll let you know.
Jan 21, 2014 at 4:19 PM
I looked at this this morning, and I note that in this case, where objects are equal according to the "Equals" function, the MultiSelector.SelectedItems property does not properly remove items from its list even when given the index of the item in the list, i.e., using IList.RemoveAt. The code seems to have been designed with the assumption of uniqueness according to the "Equals" function. Since this is framework code, IMHO, this is a Microsoft bug. Even if the control - i.e., the code in DataGrid.cs, is written to find items by reference equality, the control still breaks in this case since if you have two items in the list that are both selected and are equivalent according to Equals and you unselect one, it is never removed from the MultiSelector.SelectedItems property.

I will take the time later today or tomorrow to write this up on the Microsoft site as a bug against the MultiSelector property.

In the meantime, I have a "hack" for my case that will allow this to work properly - making the Equals function look at other fields that essentially amount to making it return reference equality instead of pure value equality.

My apologies for being difficult about it. It is clearly not an issue with the Extended DataGrid per se. Just in case you are interested, I am going to attach what I have done in DataGrid.cs to the issue link - even though it does not completely fix the issue due to the above problem.
Coordinator
Jan 21, 2014 at 5:32 PM
You can share, but cannot say for sure if I can implement it because I am looking for full proof solution.
Jan 21, 2014 at 5:59 PM
As far as I can tell, Microsoft will have to fix the MultiSelector class. Really, the code I uploaded does things a bit differently, but does not fix the problem due to the behavior of the MultiSelector class. I've posted an issue to the MS WPF forum, and linked the issue. In the issue, I added a link to my post in the WPF forum.
Jan 22, 2014 at 8:01 PM
I received a reply from someone at Microsoft. At his suggestion, I posted a bug. It appears that the issue may not exist with the .net 4.5 datagrid as indicated by his testing. At this point, however, .net 4.5 is not an option for me but should become an option in the very near future.

I'll let you know how things progress.