Bug in SortedBindingList.IndexOf

Bug in SortedBindingList.IndexOf

Old forum URL: forums.lhotka.net/forums/t/918.aspx


Baldu posted on Wednesday, August 16, 2006

SortedBindingList.IndexOf always return zero if no sort has been applied.  A simple example:


  List<string> list = new List<string>();

  string barney = "Barney";
  string charlie = "Charlie";
  string zeke = "Zeke";

  list.AddRange(new string[] { barney, charlie, zeke });

  SortedBindingList<string> sortedList = new SortedBindingList<string>(list);

  Console.WriteLine("IndexOf(charlie) (should be 1): {0}", sortedList.IndexOf(charlie));
  // writes 0

  sortedList.ApplySort(string.Empty, System.ComponentModel.ListSortDirection.Ascending);
  // the actual sort order has not changed, since the items were added "presorted"

  Console.WriteLine("IndexOf(charlie) (should be 1): {0}", sortedList.IndexOf(charlie));
  // writes 1


I couldn't find any mention of this being the expected behavior.  There's a simple workaround, of course (apply a sort immediately after creating the SortedBindingList), but I thought it was worth mentioning.


Charlie

Baldu replied on Monday, August 21, 2006

Just a little bump since I saw Rocky was hanging around today.

RockfordLhotka replied on Monday, August 21, 2006

This is a known issue and is fixed in version 2.1. You can download a pre-release of 2.1 from www.lhotka.net/cslanet/download.aspx if you'd like to test to make sure I got it right Wink [;)]  (which is really a plea on my part for testers - please DO download and try 2.1 - thanks!!)

Baldu replied on Monday, August 21, 2006

Your plea worked and I've downloaded version 2.1. 

However, the problem is still there.  In fact, a subsequent a file diff on SortedBindingList with the version from 2.0.3 shows no changes.

RockfordLhotka replied on Wednesday, August 23, 2006

Thank you, I appreciate you taking the time!
 
I have now fixed the code in cvs (V2-1 branch) so it should work properly in both sorted and unsorted modes. I also added a unit test (which I should have done in the first place) to test this. The code will look familar, as it is very close to the test you posted in this thread :)
 
Rocky
 


From: Baldu [mailto:cslanet@lhotka.net]
Sent: Monday, August 21, 2006 4:52 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Bug in SortedBindingList.IndexOf

Your plea worked and I've downloaded version 2.1. 

However, the problem is still there.  In fact, a subsequent a file diff on SortedBindingList with the version from 2.0.3 shows no changes.



Baldu replied on Wednesday, August 23, 2006

Thanks, Rocky!

Copyright (c) Marimer LLC