如果存在字符串但自定义类对象,如何在DataTable.DefaultView上使用RowFilter [英] How Can I Use RowFilter on DataTable.DefaultView if there arent Strings but a custom class-Objects

查看:120
本文介绍了如果存在字符串但自定义类对象,如何在DataTable.DefaultView上使用RowFilter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

1.我创建了一个自己的类,称为文本"(在我的命名空间"Data.Core"中).

2.我创建了一个名为"oDataTable"的数据表对象.

3.我使用以下代码在此对象上添加了一个列:

Hey guys.

1. I''ve created a Own Class, called "Text" (in my namespace "Data.Core").

2. I''ve created a DataTable-Object called "oDataTable".

3. I''ve Added a Column to this Object by using the following Code:

oDataTable.Columns.Add("Deutsch", typeof(Data.Core.Text));



4.我已经为此数据表对象创建了多个数据行,其中包含文本对象

4.我已将DataTable设置为DataGrid(WPF .Net 4.0)的ItemSource,并绑定了要在我的网格中显示的文本对象的字符串属性.
5.不,我想设置一个过滤器.我的第一个想法是使用我的
的RowFilter-Property DataTables DefaultView-Property.但是出现了一个EvaluateException:
"Can''t convert Data.Core.Text into System.String".
有没有解决此问题的常用方法,或者我可以创建一种解决方法?



4. I''ve created several DataRows to this DataTable-Object, which contains Text-Objects

4. I''ve set the DataTable to the ItemSource of a DataGrid (WPF .Net 4.0) and Bound a String-Property of my Text-Object to display in my Grid.

5. No I want to set a Filter. My First Idea was using the RowFilter-Property of my
DataTables DefaultView-Property. But there appears an EvaluateException:
"Can''t convert Data.Core.Text into System.String".
Is there a common way to handle this problem or have I to create a workaround ?

推荐答案

为类提供System.String的隐式转换运算符,请参见使用转换运算符 [
Supply your class with a implicit conversion operator for System.String, see Using Conversion Operators[^] for an explanation.


这篇关于如果存在字符串但自定义类对象,如何在DataTable.DefaultView上使用RowFilter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆