如何在网格控制C#中对整数和字符串进行排序?这是我的代码:



这是类:

public static List<MasterReject> GetData()
{
var context = new FingerScanContext();
return (from a in context.MasterRejects
select a).ToList();
}

这就是我所说的网格视图:

 InitializeComponent();
 List<MasterReject> mrj = new List<MasterReject>();
 gridView2.OptionsBehavior.Editable = false;
 mrj = MasterReject.GetData();
 gridView.DataSource = mrj;
 searchLookItem.Properties.DisplayMember = "ItemName";
 searchLookItem.Properties.ValueMember = "ItemID";

如果我理解你的问题,那么你可以简单地这样做:

public static List<MasterReject> GetDatas()
{
    var context = new FingerScanContext();
    // assuming that Id is the primary key and you want to sort on that
    return context.MasterRejects.OrderBy(m=> m.Id).ToList();
}

试试这个

public static List<MasterReject> GetDatas()
{
    var context = new FingerScanContext();
    return context.MasterRejects.OrderBy(m=>Regex.Split(m.Replace("
    ", ""), "([0-9]+)")
   ).ToList();
}

相关内容

  • 没有找到相关文章

最新更新