views:

44

answers:

1

Hello, first post here but I'm a frequent visitor =)

I have a WPF application with .NET 4.0 and Visual Studio 2010 which uses DataViews (coming from an SQL Server 2008). I have two tables which looks like this

Table1

GUID (Primary Key, UniqueIdentifier)
Table2_GUID (UniqueIdentifier)

Table2

GUID (Primary Key, UniqueIdentifier)

First of all I've been having trouble using the RowFilter on the DataView with Guid columns so I've added string columns to the tables called GUID_S, Table2_GUID_S etc. These columns contain the GUID converted to a string. (c0d2bd01-68fd-4d8a-a211-a703e8ec7edd => 01BDD2C0FD688A4DA211A703E8EC7EDD)

When I try to bind to the GUID_S columns everthing works as expected but when I try to bind to the GUID columns all I get is "DependencyProperty.UnsetValue" in the converter. Then I tried with creating a class called GuidClass, containing nothing but a Guid property, and then the binding works. Can anyone tell my why this is?

My 3 bindings looks like this

// 1. Working  
Binding bindingGuidS = new Binding();  
bindingGuidS.Source = dataRowView;  
bindingGuidS.Path = new PropertyPath("GUID_S"); // string column  
multiBinding.Bindings.Add(bindingGuidS);  

// 2. Not Working - "DependencyProperty.UnsetValue"  
Binding bindingGuid = new Binding();  
bindingGuid.Source = dataRowView;  
bindingGuid.Path = new PropertyPath("GUID"); // Guid column  
multiBinding.Bindings.Add(bindingGuid);  

// 3. Working  
Guid guid = (Guid)dataRowView["GUID"];  
GuidClass guidClass = new GuidClass(guid);  
Binding bindingGuid = new Binding();  
bindingGuid.Source = guidClass;  
bindingGuid.Path = new PropertyPath("TheGuid");  
multiBinding.Bindings.Add(bindingGuid);  

and the GuidClass just looks like this

public class GuidClass  
{  
    public GuidClass(Guid guid)  
    {  
        TheGuid = guid;  
    }  

    public Guid TheGuid
    {
        get;
        set;
    }
}  

Thanks for your help /Fredrik

A: 

I set the DataBindings in the Output window to "All". Then I got the hashcode for the failing DataRowView from the Output window and then I noticed that the column that I were using as Path was called "Guid" and not "GUID". Can't believe I missed that :) Must have renamed it by mistake

Meleak