RadGridView Column Binding to Second level property

11 posts, 0 answers
  1. Xavier
    Xavier avatar
    2 posts
    Member since:
    Aug 2011

    Posted 19 Feb 2014 Link to this post

    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!




































  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 24 Feb 2014 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Dimitrios
    Dimitrios avatar
    5 posts
    Member since:
    Jul 2016

    Posted 02 Sep Link to this post

    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?

  5. David
    David avatar
    20 posts
    Member since:
    Jan 2012

    Posted 05 Sep in reply to Dimitrios Link to this post

    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

     

  6. Dimitrios
    Dimitrios avatar
    5 posts
    Member since:
    Jul 2016

    Posted 05 Sep Link to this post

    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!).

  7. David
    David avatar
    20 posts
    Member since:
    Jan 2012

    Posted 05 Sep in reply to Dimitrios Link to this post

    I have serveral bindings in my application with nested bound properties.
    So one "ApprovalPath"-Item contains "Order" and "User" property?
  8. Dimitrios
    Dimitrios avatar
    5 posts
    Member since:
    Jul 2016

    Posted 05 Sep in reply to David Link to this post

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

    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?

  9. David
    David avatar
    20 posts
    Member since:
    Jan 2012

    Posted 05 Sep Link to this post

    Hi Dimitrios,

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

    Did I anything different?

     

  10. Dimitrios
    Dimitrios avatar
    5 posts
    Member since:
    Jul 2016

    Posted 05 Sep in reply to David Link to this post

    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!

  11. Dimitrios
    Dimitrios avatar
    5 posts
    Member since:
    Jul 2016

    Posted 05 Sep Link to this post

    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!

  12. Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    371 posts

    Posted 07 Sep Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready