Hello,
I have a GridView with GroupComparer and it works fine, but if I add EnableCustomSorting true, the GroupComparer stops working, it's not called by GridView anymore. Could you please advise how to make it work together.
public
Form1()
{
InitializeComponent();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"A"
,
typeof
(
string
) );
this
.radGridView1.Columns.Add(
"A"
);
this
.radGridView1.Columns.Add(
"B"
);
this
.radGridView1.Rows.Add(
"1"
,
"1"
);
this
.radGridView1.Rows.Add(
"2"
,
"2"
);
this
.radGridView1.Rows.Add(
"10"
,
"10"
);
this
.radGridView1.MasterTemplate.GroupComparer =
new
GroupComparer();
this
.radGridView1.CustomSorting += RadGridView1_CustomSorting;
this
.radGridView1.EnableCustomSorting =
true
;
//if true, GroupComparer stop working
}
private
void
RadGridView1_CustomSorting(
object
sender, GridViewCustomSortingEventArgs e )
{
//logic to sort columns.
}
public
class
GroupComparer : IComparer<Group<GridViewRowInfo>>
{
public
int
Compare( Group<GridViewRowInfo> x, Group<GridViewRowInfo> y )
{
int
parsedX;
int
parsedY;
if
(
int
.TryParse( ( (
object
[])x.Key ).First().ToString(),
out
parsedX ) &&
int
.TryParse( ( (
object
[])y.Key ).First().ToString(),
out
parsedY ) )
{
int
result = parsedX.CompareTo( parsedY );
DataGroup xGroup = x
as
DataGroup;
if
( xGroup !=
null
&& ( (DataGroup)x ).GroupDescriptor.GroupNames.First().Direction == ListSortDirection.Descending )
{
result *= -1;
}
return
result;
}
return
( (
object
[])x.Key )[0].ToString().CompareTo( ( (
object
[])y.Key )[0].ToString() );
}
}