【发布时间】:2012-08-24 17:06:51
【问题描述】:
我有一个数据绑定的 DataGridView,我正在尝试使用 IComparer 对其进行排序。
当我尝试应用我的排序时,我收到了这个错误:
DataGridView 控件是数据绑定的。控件不能使用比较器来执行排序操作。
我的排序技术基于this link。
仅供参考,我试图通过使用它们的标记值来比较位图。
public int Compare(object x, object y)
{
DataGridViewRow DataGridViewRow1 = (DataGridViewRow)x;
DataGridViewRow DataGridViewRow2 = (DataGridViewRow)y;
// Try to sort based on the tag
int CompareResult = System.String.Compare(
DataGridViewRow1.Cells[1].Tag.ToString(),
DataGridViewRow2.Cells[1].Tag.ToString());
return CompareResult * sortOrderModifier;
}
【问题讨论】:
标签: c# winforms datagridview