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

Bind IsReadOnly of Column to Property of Item in ItemsSource

4 Answers 93 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 13 Jul 2010, 06:18 PM
Hi,

I want the IsReadOnly property of a column to be based on the value of a property of the business object the row is bound to. Say, if one property of the business object the row is bound to is true, the IsReadOnly property of the other column should also be true; however, it seem that the DataContext at the column level is not that of the row but of the parent. So I have my DataContext bound to a ViewModel and the GridView to a collection property of the ViewModel. I get an error from the grid like:

System.Windows.Data Error: BindingExpression path error: 'MyBoolProperty' property not found on 'ViewModel' ViewModel' (HashCode=769899). BindingExpression: Path='MyBoolProperty' DataItem='ViewModel' (HashCode=769899); target element is 'Telerik.Windows.Controls.GridViewDataColumn' (Name='null'); target property is 'IsReadOnly' (type 'System.Boolean')..


How do I go about doing this with the GridView?

Thanks in advance,

Carlos

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 14 Jul 2010, 06:17 AM
Hello Carlos,

 Indeed grid columns DataContext is actually the grid DataContext. Why not use CellEditTemplateSelector to load conditionally different template for edit mode?

Best wishes,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Carlos
Top achievements
Rank 1
answered on 14 Jul 2010, 09:24 PM
Thanks for the reply, but that only gets me part of the way there. Using the CellEditTemplateSelector allows me to choose when to use a read only textbox when in edit mode, but I also need to make the text gray when the cell isn't being edited based on the same condition used to pick whether or not the cell is readonly. How would I go about doing that?

Thanks in advance,

Carlos
0
Carlos
Top achievements
Rank 1
answered on 14 Jul 2010, 09:29 PM
I think I just figured it out...Let me know if this is correct, but I'm assuming it would be using the CellStyleSelector?
0
Accepted
Vlad
Telerik team
answered on 15 Jul 2010, 06:58 AM
Hi Carlos,

Indeed you can use CellStyleSelector as well. 

Sincerely yours,
Vlad
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Carlos
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Carlos
Top achievements
Rank 1
Share this question
or