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

Binding other properties to row item

4 Answers 668 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 04 Aug 2016, 06:45 AM

Hello,

I have a I think very simple question but I cant find any solution for it. Its about binding other properties, besides the DataMemberBinding to the current item. 

The scenario is as follows, I have a data object which is setup as follows:

public class EmployeeViewModel
{
    public Employee EmployeeData { get; set; }
 
    public EmployeeViewState ViewState { get; set; }
}
 
public class Employee
{
    public string Name { get; }
}
 
public class EmployeeViewState
{  
    public bool ColumnNameReadOnly = true;
}

 

In my main viewmodel I have the following:

public class ViewModel
{
    public ObservableCollection<EmployeeViewModel> Employees { get; set; }
 
}

 

Now I want to bind my view to this collection, I have the following XAML:

<telerik:RadGridView x:Name="grid" MinHeight="400"
                    DataContext="{Binding}"
                    ItemsSource="{Binding Employees}">
    <telerik:RadGridView.Columns>
        <telerik:GridViewDataColumn Header="Name:"
                                    DataMemberBinding="{Binding Path=EmployeeData.Name}"                                                    
                                    Width="215"
                                    IsReadOnly="{Binding Path=ViewState.ColumnNameReadOnly}"/>
    </telerik:RadGridView.Columns>
</telerik:RadGridView>

 

The Name property of the EmployeeData object is correctly bind to the current item of the row, but the IsReadOnly property binding is looking for a ViewState object in my main viewmodel!

How can I set the datacontext for this property the same as with the DataMemberBinding?

 

Regards,

 

Marcel

4 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 05 Aug 2016, 10:05 AM
Hello Marcel,

In this particular scenario, you should use the IsReadOnlyBinding property rather than the IsReadOnly property.

I'm attaching a sample project to demonstrate how you should use it in this case. I hope you find it helpful.

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.
0
Marcel
Top achievements
Rank 1
answered on 05 Aug 2016, 10:58 AM

Hello Dilyan,

Thanks this works great, but when I have other properties that I also want to bind to the particular row business object (for example the TabStopMode or IsEnabled  properties) how would I do this?

 

 

Regards,

 

Marcel

0
Accepted
Dilyan Traykov
Telerik team
answered on 05 Aug 2016, 12:09 PM
Hello Marcel,

Setting these properties on a cell/row level can be achieved by using RadPropertyGrid's CellStyleSelector and RowStyleSelector properties.

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.
0
Marcel
Top achievements
Rank 1
answered on 10 Aug 2016, 03:28 PM

Thanks, Dilyan.

This got me a little further.

Regards,

Marcel

Tags
GridView
Asked by
Marcel
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
Marcel
Top achievements
Rank 1
Share this question
or