Click here to Skip to main content
11,932,402 members (54,042 online)
Rate this:
Please Sign up or sign in to vote.
See more: DataTable DataGrid
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. 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 ?
Posted 29-Sep-11 22:28pm
Edited 29-Sep-11 23:04pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Supply your class with a implicit conversion operator for System.String, see Using Conversion Operators[^] for an explanation.
Jeff.Jefferson 11-Oct-11 2:38am
That really works ?

I've put these code in my "Text"-Class.
<pre lang="c#">
public static implicit operator string(Text t)
return t.Caption;

Caption is a string-Property of my Text-Class.

The same Error occurs :-S

But i have a question to the Conversion operators....

Can there occur a conflict by implement this Conversion for Strings and a "override ToString()-Method" ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.1 | Last Updated 30 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100