views:

78

answers:

1

hi, I have a User table and I have a foreign key of this table from a Book table. the FK is ProxyResponsibleUser_ID. when I use DataGridTextColumn in my DataGrid anything is OK but now I want to use DataGridTemplateColumn to display the FullName column from User table for corresponding user with ProxyResponsibleUser_ID. I get an error since DataGridTemplateColumn does not have a Binding property.

So, by which property of DataGridTemplateColumn will I bind the ProxyResponsibleUser_ID? Thanks in advance.

<DataGridTextColumn x:Name="securityConfigurationNameColumn" Binding="{Binding Path=SecurityConfigurationName}" Header="Security Configuration Name" Width="*" />
<DataGridTemplateColumn x:Name="proxyResponsibleUser_IDColumn"   Binding="{Binding Path=ProxyResponsibleUser_ID}" Header="Proxy Responsible User ID" Width="*" >
                <DataGridTemplateColumn.CellEditingTemplate>
                    <DataTemplate DataType="{x:Type domain:User}">
                        <TextBlock Text="{Binding FullName}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
+1  A: 

I don't see exactly what you want to do, but the Binding has to be done at the TextBlock exactly as you already did. Therefore the Binding in the DataGridTemplateColumn-Tag is needless. There is no need for the column to know the id of the record.

If you want to have the id available to the TextBox-control (commonly not needed because you have access to this property directly through the DataContext), you can do this for example by binding the Tag-property.

<TextBlock Text="{Binding FullName}" Tag="{Binding ProxyResponsibleUser_ID}"/> 

By the way, you declared a TextBlock in the EditTemplate. Maybe you want a TextBox. Or do you want to allow the user to change the Id? Make a comment if this is the case.

Hope this helps.

HCL
Normally I was using DataGridTextColumn to display the FullName via the User navigation by Entity FrameWork. When I change a combobox's selected item, I want the datagrid value to be updated but when I do so, there had been update problems. bur when I use directly the proxyResponsibleUser_ID, it is automatically updated but in data grid Id values are displayed instead of Fullname. So I tried such a code snippet. Thanks for your help but it didn't work. Can you suggest a solution for such a problem?Thank you again..
cemregoksu
No I dont want anybody to edit the column, I used it by mistake :p now I used celltemplate
cemregoksu
Sounds to me as an EF-problem (synchronizing between key and navigation-property). But I'm sorry, I have no knowledge about EF and therefore can not help you in this case. However for the question you wrote, DataGridTemplateColumn has no need to know the Binding. All binding-specific declaration is done in the DataTemplate/s. I would try to ask a more EF-specific question to get a more valuable answer than mine (my answer is only WPF-specific).
HCL