This is a migrated thread and some comments may be shown as answers.

Filter definition using uniqueidentifier

1 Answer 65 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Doug
Top achievements
Rank 1
Doug asked on 02 Sep 2011, 02:35 PM
Hi,

I have a database column which is a uniqueidentifer type (its a Guid) within SQL Server and I cannot currently get it to work as part of the filter definitions for the GridView. Currently I try to treat it as a string as below but then the application crashes and an error is thrown something like

No coercion operator is defined between types 'System.Guid' and 'System.String'.

This is how i have it defined in the xaml up til now

<dataFilter:ItemPropertyDefinition PropertyName="Guid" PropertyType="{Binding String, Source={StaticResource Types}}" DisplayName="Guid"/>

The options I would like to use with this are is equal and not equal. these are probably the only ones that make sense for this type.

How can I use a uniqueidentifer with the Data Filter?

Thanks for your help
Doug

1 Answer, 1 is accepted

Sort by
0
Accepted
Rossen Hristov
Telerik team
answered on 05 Sep 2011, 08:58 AM
Hello Doug,

If the actual type of the property is a GUID, then it cannot be treated as a string, because comparisons have to be made and GUIDs and string don't compare to each other out-of-the-box. 

Here is what can be done. RadDataFilter has a feature known as Custom Filter Editors. This feature allows you to provide a specialized editor for more exotic types. RadDataFilter can handle the basic types out of the box, i.e. it will spawn a RadDateTimePicker for DateTime's, a RadMaskedTextBox for numeric types, TextBox for strings and so on. But when the type is not among these basic supported types, the developer can provide its own editor which "knows" how to handle the exotic type.

The rule of thumb is that if the actual data Type is a Guid, then the editor should "produce" a Guid. Just like the RadDateTimePicker produces a DateTime and so on.

So you can create some kind of very simple "smart" TextBox which parses its Text and "produces" a Guid based on that. But it can be anything else, as long as it "produces" actual Guid instances.

An easier approach would be to "shape" your data before it gets to RadDataFilter if you are allowed to do that. For example, you can add an additional read-only string property that will return the actual GUID.ToString(). Then filter on this new string property in RadDataFilter and not on the real Guid one. You will get string filtering out-of-the-box and you will not have to create any custom filter editors. But that is, if you are allowed to modify your object model.

I hope this helps. Let me know if you have any other questions.

Greetings,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
DataFilter
Asked by
Doug
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or