If your database is not set up to easily access the other fields in the selected item, then you will have to add code to find the right selected item. Below is some code that uses a dataview to do this, but there are other options as well. (You could even loop through the DataTable looking for the proper row. Or, if you set the id up as a primary key, you could use Datatable.Find.))
public class ComparerClass : IComparer
{
private DataTable dt;
private DataView dv;
public ComparerClass(DataTable dt)
{
this.dt = dt;
this.dv = new DataView(dt, "", "", DataViewRowState.CurrentRows);
}
public int Compare(object x, object y)
{
GridStyleInfo styleX = new GridStyleInfo(x as GridStyleInfoStore);
GridStyleInfo styleY = new GridStyleInfo(y as GridStyleInfoStore);
string sx = "";
string sy = "";
dv.RowFilter = string.Format("[id] = {0}", styleX.CellValue);
if(dv.Count > 0)
{
sx = dv[0]["color"].ToString();
}
dv.RowFilter = string.Format("[id] = {0}", styleY.CellValue);
if(dv.Count > 0)
{
sy = dv[0]["color"].ToString();
}
return sx.CompareTo(sy);
}
}