Can a NameValueList be sorted?

Can a NameValueList be sorted?

Old forum URL:

stevenkahan posted on Friday, September 17, 2010

We are upgrading our winforms application from .NET 1.x to 2.0

In our original CSLA Code (CSLA Extentinons) we implemented a BindableNameValueList, Inheriting from CSLA.NameValueList and a SortComparer Class which allowed us to sort a BindableNameValueList object by the value.  Their primary use is binding to comboboxes.

During our upgrade we converted all the BindableNameValueList objects to NameValueListBase(of K,V)

We then realized we had not sorted the NVL objects and attempted to do this by using SortedBindingList .

This did not work as it seems that NVL does not implement IList(of T) [is this true? I am confused about this...] 

error: Unable to cast object of type 'PlanServicesLibrary.LicenseStatus' to type 'System.Collections.Generic.IList`1[PlanServicesLibrary.LicenseStatus]'."

Public  Class LicenseStatus
Inherits NameValueListBase(Of String, String)

My question(s) are:

1.  Are we wrong and we should be able to use SortedBindingList?

2.  Should we just sort the data as we populate the NVL?

3.  Should we use something other than NVL?





RockfordLhotka replied on Friday, September 17, 2010

I think at that time I was using Microsoft's key/value collection type as a base. In more recent versions of CSLA I switched to subclass ReadOnlyBindingList, which ultimately is a subclass of BindingList<T>.

If you are moving to .NET 2, I strongly recommend you at least move to CSLA 3.0.5, or use the N2 release which is basically 3.7, but running on .NET 2.0.

You should absolutely avoid CSLA .NET 2.0 in favor of at least 2.1 - but 3.0.5 is the recommended release for .NET 2.0.

And in 3.0.5 NLVB inherits from ReadOnlyBindingList, which will probably address your issue.

stevenkahan replied on Friday, September 17, 2010

By knowing that this should work we continued to investigate our code (we are using CSLA 3.0.5) and realized that we were passing the wrong object to SortedBindingList.

(We had SortedBindingList (of <List>) instead of <List.NameValuePair>)

Thank you for your help.  Big Smile

Copyright (c) Marimer LLC