soorraj
asked on
Sorting a Collection<t>
I am trying to do a sort for Collection<T>. I have the VB code that works fine. But i want to do it in C#. I used the developer fusion to convert the code form VB.NET to C#. When i build the C# code it has many errors.
The CarModel collection calls the SortableBindingList
public class CarModelCollection : SortableBindingList<CarMod al>
I have attached the VB version of Sort , C# ver of code and my code.
The errors are in the SortableBindingList.cs
below error is on this line
public class SortableBindingList<T>: BindingList<T>,ISortableBi ndingList
SortableBindingList<T>' does not implement interface member 'ISortableBindingList.Appl ySortCore( System.Com ponentMode l.Property Descriptor , System.ComponentModel.List SortDirect ion)'. 'SortableBindingList<T>.Ap plySortCor e(System.C omponentMo del.Proper tyDescript or, System.ComponentModel.List SortDirect ion)' cannot implement an interface member because it is not public.
'SortableBindingList<T>' does not implement interface member 'ISortableBindingList.Supp ortsSortin gCore'.
'System.ComponentModel.Bin dingList<T >.Supports SortingCor e' cannot implement an interface member because it is not public.
List<T> items = this.Items; gives this error
Cannot implicitly convert type 'System.Collections.Generi c.IList<T> ' to 'System.Collections.Generi c.List<T>' . An explicit conversion exists
(are you missing a cast?)
CarModal.txt
CarModelCollection.txt
ISortableBindingList.txt
PropertyComparer.txt
SortableBindingList.txt
ISortableBindingListVB.txt
PropertyComparerVB.txt
SortableBindingListVB.txt
The CarModel collection calls the SortableBindingList
public class CarModelCollection : SortableBindingList<CarMod
I have attached the VB version of Sort , C# ver of code and my code.
The errors are in the SortableBindingList.cs
below error is on this line
public class SortableBindingList<T>: BindingList<T>,ISortableBi
SortableBindingList<T>' does not implement interface member 'ISortableBindingList.Appl
'SortableBindingList<T>' does not implement interface member 'ISortableBindingList.Supp
'System.ComponentModel.Bin
List<T> items = this.Items; gives this error
Cannot implicitly convert type 'System.Collections.Generi
(are you missing a cast?)
CarModal.txt
CarModelCollection.txt
ISortableBindingList.txt
PropertyComparer.txt
SortableBindingList.txt
ISortableBindingListVB.txt
PropertyComparerVB.txt
SortableBindingListVB.txt
ASKER
I need to make it work the way i am doing. BY changing to public new it complies but it doesn't work.
Ah, that's probably due to the fact that you use it differently, sort from the grid? Can you share some more code?
ASKER
This is what i have. It is in Winforms. But that should not matter i guess for applying the sort.
There are 4 projects.
Business Layer - CarModal.cs, CarModalManager.cs, CarModalCollection.cs
DataAccess Layer - CarModalDB.cs
MyUtilities- Have the three sort programs that i uploaded before
Presentation - Form.cs
Which has the code
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = CarModalManager.GetList();
}
CarModalManager.txt
CarModalDB.txt
There are 4 projects.
Business Layer - CarModal.cs, CarModalManager.cs, CarModalCollection.cs
DataAccess Layer - CarModalDB.cs
MyUtilities- Have the three sort programs that i uploaded before
Presentation - Form.cs
Which has the code
private void Form1_Load(object sender, EventArgs e)
{
dataGridView1.DataSource = CarModalManager.GetList();
}
CarModalManager.txt
CarModalDB.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help. It works your way too. But i am just curious why i am not able to use the Interface. Probably it is different in c#.
- on the "ISortableBindingList" in SortableBindingList.cs you can hover and then choose from the submenu: Implement interface. Then you can see that the method signatures were wrong, globally speaking they all had to be "public new ..." instead of "protected override"
- use a cast for the "cannot implicitly convert" error on Items.
I have now:
Open in new window
Now at least it compiles. I'm in the process of testing...