J
Jose
Dear All,
I have been staring at this for ages now and I still can't see why it
doesn't work. Any help will be GREATLY appreciated.
I am simply trying to sort an arraylist using my own instance of
IComparer. Code below...
Quite simply it doesn't work. Can anyone see where I'm going wrong?
Thanks in advance,
Jose
<code>
public class TabDetail
{
public int ID;
public string Name;
public int Order;
public string URL;
}
public class TabOrderComparer: IComparer
{
public int Compare(object o1, object o2)
{
int SortID1 = ((TabDetail)o1).SortID;
int SortID2 = ((TabDetail)o2).SortID;
return SortID1.CompareTo(SortID2);
}
}
public class TabSettings
{
public ArrayList Tabs;
public int ActiveTab;
public TabSettings()
{
this.Tabs = new ArrayList();
PopulateTabs();
this.Tabs.Sort(new TabOrderComparer());
}
private void PopulateTabs()
{
Classes.DataAccessor oDA = new Classes.DataAccessor();
DataTable dtTabs = oDA.ReadTabs();
foreach(DataRow drTab in dtTabs.Rows)
{
TabDetail oTab = new TabDetail();
oTab.ID = (int)drTab["ID"];
...
//Populate the rest of the properties here...
}
}
}
</code>
I have been staring at this for ages now and I still can't see why it
doesn't work. Any help will be GREATLY appreciated.
I am simply trying to sort an arraylist using my own instance of
IComparer. Code below...
Quite simply it doesn't work. Can anyone see where I'm going wrong?
Thanks in advance,
Jose
<code>
public class TabDetail
{
public int ID;
public string Name;
public int Order;
public string URL;
}
public class TabOrderComparer: IComparer
{
public int Compare(object o1, object o2)
{
int SortID1 = ((TabDetail)o1).SortID;
int SortID2 = ((TabDetail)o2).SortID;
return SortID1.CompareTo(SortID2);
}
}
public class TabSettings
{
public ArrayList Tabs;
public int ActiveTab;
public TabSettings()
{
this.Tabs = new ArrayList();
PopulateTabs();
this.Tabs.Sort(new TabOrderComparer());
}
private void PopulateTabs()
{
Classes.DataAccessor oDA = new Classes.DataAccessor();
DataTable dtTabs = oDA.ReadTabs();
foreach(DataRow drTab in dtTabs.Rows)
{
TabDetail oTab = new TabDetail();
oTab.ID = (int)drTab["ID"];
...
//Populate the rest of the properties here...
}
}
}
</code>