过滤包含对象的DataTable

时间:2015-05-21 15:58:21

标签: c# .net datatable

在我DataTable填充string值之前。 我使用Select方法过滤数据,效果非常好。

DataRow[] drs = dataTable.Select("[" + dataTable.Columns[columnIndex].ColumnName + "] LIKE '%" + filter + "%'");

一段时间后,string中的DataTable值必须更改为Cell个对象,这是一个包含旧值和其他一些属性的自制类。

public class Cell
{
    public object Value { get; set; } /*This is the old string value*/
    public bool Property1 { get; set; }
    public int Property2 { get; set; }
    public string Property3 { get; set; }
}

我意识到我的过滤功能不再适用了。

任何人都知道我应该如何处理现在包含DataTable个对象而不是Cell的{​​{1}}的过滤?

1 个答案:

答案 0 :(得分:0)

感谢kanchirks评论,我提出了这个解决方案。

EnumerableRowCollection erc = dataTable.AsEnumerable().Where(dr => ((Cell)dr[columnIndex]).Value.ToString().ToLower().Contains(filter.ToLower()));
相关问题