【发布时间】:2016-09-01 16:24:11
【问题描述】:
我有一个数据表,其中一列是特定类型的对象,比如 typeOf(A) - A 是我的自定义类。 A 类具有文本属性和其他属性,如 bool。从用户或外部代码中,我只获得要在 RowFilter 中用于过滤的文本值,在下面的示例中,我将获得“cat”作为我要使用的过滤器。使用这个如何创建 RowFilterExpression?
class A
{
public string Text{get;set;}
public bool isReadonly {get;set;}
}
DataTable table = new DataTable();
table.Columns.Add("col1", typeOf(A));
table.Rows.Add(new A{Text = "cat", isReadOnly = true,})
table.Rows.Add(new A{Text = "dog", isReadOnly = false,})
string filter = "cat";
DataView dataView = new DataView(table);
dataView.RowFilter = "[col1]='"+filter+"'";
上面的表达式不起作用,因为它试图将它与单元格中的对象匹配。如何使用此过滤器表达式单独过滤掉第一行?
感谢任何帮助。
【问题讨论】: