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
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?
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
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!).
So one "ApprovalPath"-Item contains "Order" and "User" property?
[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?
Hi Dimitrios,
i wrote some Code based on your explenations, but i dont have any Problems with it (see attachments).
Did I anything different?
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!
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!
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