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

RadGridView Column Binding to Second level property

10 Answers 381 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Xavier
Top achievements
Rank 1
Xavier asked on 19 Feb 2014, 04:02 PM
Hi,

   I'm trying to bind the RadGridView column to a second level property. This is my code:

...
<telerik:RadGridView x:Name="GridView" Loaded="GridView_Loaded" ItemsSource="{Binding ViewMember.TelerikView}"/>
...

private void GridView_Loaded(object sender, RoutedEventArgs e)
{
    foreach (var f in ViewMember.Data.Fields)
    {
        var col = new Telerik.Windows.Controls.GridViewDataColumn();
        col.Header = f;
        col.DataMemberBinding = new Binding(f);//f is Country.Name
        col.UniqueName = f;
        GridView.Columns.Add(col);
    }
}

When f is ID it works fine, but when its Country.Name the column is showed but the row is empty. How can i fix this behavior?


Thanks!




































10 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 24 Feb 2014, 12:07 PM
Hello,

The Binding on a nested property should work fine. Does the bound business object has a property Country which has a property Name? What is the result if you define the column in XAML?

Regards,
Didie
Telerik
0
Dimitrios
Top achievements
Rank 1
answered on 02 Sep 2016, 05:43 PM

Hello,

sorry for digging up an old message but I have a similar problem.

I used to have a DataGrid with a nested property like that and it worked fine:

<DataGrid ItemsSource="{Binding SelectedItem.ApprovalPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
          SelectedItem="{Binding SelectedPathUser}"
          AutoGenerateColumns="False"
          CanUserDeleteRows="False"
          Height="100"
          IsReadOnly="True"
          >
 
    <DataGrid.Columns>
        <DataGridTextColumn Header="Name" Binding="{Binding Path=User.DisplayName}" Width="*" />
        <DataGridTextColumn Header="Order" Binding="{Binding Order, UpdateSourceTrigger=PropertyChanged}" Width="45" />
    </DataGrid.Columns>
</DataGrid>

 

 

 

I switched to RadGridView, trying to achieve the same functionality but I got an error that it cannot find the specified property!

<telerik:RadGridView ItemsSource="{Binding SelectedItem.ApprovalPath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                     SelectedItem="{Binding SelectedPathUser}"
                     AutoGenerateColumns="False"
                     CanUserDeleteRows="False"
                     Height="100"
                     IsReadOnly="True"
                     >
 
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Name" DataMemberBinding="{Binding User.DisplayName}" Width="*" />
        <telerik:GridViewDataColumn Header="Order" DataMemberBinding="{Binding Order, UpdateSourceTrigger=PropertyChanged}" Width="45" />
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

While debugging I found out that it is trying to find the property "DisplayName" from the selected item object and to from the nested property of User!

Am I doing something wrong with the binding or it is a problem with bindings?

0
David
Top achievements
Rank 1
answered on 05 Sep 2016, 08:07 AM

Hi Dimitrios,

when I see your Binding, you try to find "User" on ApprovalPath right?
It is hard to understand the code, when there is no description of the data.

Just for help to get through the code: ItemsSource Bindings should be named as plural. ItemsSource = employees (for example).
SelectedItem = SelectedEmployee.

Maybe it is better to understand for other guys.

David

 

0
Dimitrios
Top achievements
Rank 1
answered on 05 Sep 2016, 11:26 AM

Hello David!

Thank you for your reply and your recommendations on naming conventions.

My problem is that it used to work with DataGrid but when I switched to RadGridView with the same properties it is not working!I have used other times second level property binding and it is working fine. The problem comes, as I see it, when I bind to a second level property of a second level collection!

In this case I am trying to bind to User.DisplayName of the selected item from second level collection SelectedItem.ApprovalPath (if that makes any sense!).

0
David
Top achievements
Rank 1
answered on 05 Sep 2016, 12:20 PM
I have serveral bindings in my application with nested bound properties.
So one "ApprovalPath"-Item contains "Order" and "User" property?
0
Dimitrios
Top achievements
Rank 1
answered on 05 Sep 2016, 01:10 PM

[quote]David said:I have serveral bindings in my application with nested bound properties.
So one "ApprovalPath"-Item contains "Order" and "User" property?[/quote]

Yes, on "ApprovalPath"-item contains "Order" and "User" properties! Let me clarify the usage a little more:

I have a Deployment class that contains a collection of DeploymentApprovalPath objects as follows:

public class Deployment
{
    public virtual ObservableCollection<DeploymentApprovalPath> ApprovalPath { get; set; }
}
 
public class DeploymentApprovalPath
{
    public virtual User User { get; set; }
    public int Order { get; set; }
}

In my view I have a RadGridView that binds to a collection of Deployments and the selected Deployment is the SelectedItem (lets name it SelectedDeployment for convenience).
Then I have the next RadGridView that binds to the SelectedDeployment.ApprovalPath so I can display the approval path of the specific deployment (list of users with a specific order). The SelectedItem of this specific ApprovalPath (DeploymentApprovalPath type) is bound to the SelectedPathUser property.
I want the user of the app to be able to add new Users to the approval path and set its order (new DeploymentApprovalPath object in SelectedDeployment.ApprovalPath ). So I created a Combobox with the following bindings:

Items="{Binding AvailableUsers}" DisplayMemberPath="DisplayName" SelectedItem="{Binding SelectedPathUser.User, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}

So the user can select the specific User from a list of available Users and it automatically set it to the SelectedDeployment.ApprovalPath.SelectedPathUser.User !

Does it make any sense?

0
David
Top achievements
Rank 1
answered on 05 Sep 2016, 01:36 PM

Hi Dimitrios,

i wrote some Code based on your explenations, but i dont have any Problems with it (see attachments).

Did I anything different?

 

0
Dimitrios
Top achievements
Rank 1
answered on 05 Sep 2016, 01:39 PM

No, everything seems the same. The only difference is that I have a button to add new DeploymentApprovalPath and a combobox from where I select the User I want to add!

0
Dimitrios
Top achievements
Rank 1
answered on 05 Sep 2016, 02:24 PM

I tried to create a small project and recreate the issue but unfortunately I'm not able to do so!

I'll try to figure out what is going on and repost if I find something!

Thank you for your effort!

0
Dilyan Traykov
Telerik team
answered on 07 Sep 2016, 08:25 AM
Hello Dimitrios,

Unfortunately, I'm also unable to reproduce the issue you've described at my end.

Could you please try isolating the issue in a sample project and either providing an address where I could download it or opening a new support ticket and attaching it there so that I may further assist you in finding a solution?

Thank you in advance for your cooperation on the matter.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Xavier
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Dimitrios
Top achievements
Rank 1
David
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or