Click here to Skip to main content
11,802,442 members (71,523 online)
Rate this: bad
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 21:28pm
Edited 29-Sep-11 22: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 at 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
0 KrunalRohit 366
1 OriginalGriff 365
2 F-ES Sitecore 295
3 Afzaal Ahmad Zeeshan 230
4 CPallini 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.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