ObjectListView Bug in constructor

ObjectListView Bug in constructor

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


JoeFallon1 posted on Friday, September 01, 2006

Brian,

I am testing the ObjectListView and did not get very far. There seems to be a bug in one of the constructors. Here is the code:

public ObjectListView(IList list, string propertyName, ListSortDirection direction, string filter)

: this(list, TypeDescriptor.GetProperties(list.GetType().GetProperty("Item").PropertyType)[propertyName], direction, filter)

{

}

My collection class has an overloaded Item Property so you can find an Item by the PK as well as the Index. This causes the costructor above to crash with this exception:

'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll

Additional information: Ambiguous match found.

I think it is rather common to have such overloads.

Do you think you can fix this?

Thanks.

Joe

============================================================

PS - I will try some of the other constructors for now.

 

============================================================

Same problem occurs in this constructor only further down:

public ObjectListView(IList list, ListSortDescriptionCollection sorts, string filter)

{

if (filter == null) filter = string.Empty;

_list = list;

_indexedType = _list.GetType().GetProperty("Item").PropertyType;

 

 

 

 

Brian Criswell replied on Friday, September 01, 2006

Hi Joe,

Thanks for the feedback.  I am assuming you still have the default indexer and your overloaded version indexes by string or Guid?

Brian Criswell replied on Friday, September 01, 2006

Hi Joe,

I did some poking around and have changed all places where it was trying to find the return type of the Item property to specify the Item property that is indexed by an integer (which all IList should have).  This seems to work with a list that has two Item properties, one indexed by an integer and the other indexed by a Guid.  I have updated the version on CodePlex.  Would you be willing to try it?

Cheers,
Brian

JoeFallon1 replied on Saturday, September 02, 2006

Hey Brian,

Sure I would like to try it. Thanks for making the fix so quick.

Joe

 

JoeFallon1 replied on Saturday, September 02, 2006

Hi Brian,

I just ran a quick test and got past the bug in the constructor. Nice solution.

I bound it to a web page grid and it all works very well.

I think I may end up using it in my project after I test it some more.

But so far so good!

Thanks.

Joe

Copyright (c) Marimer LLC