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

Columns IsReadOnly not effecting CellTemplate

1 Answer 34 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shawn
Top achievements
Rank 1
Shawn asked on 30 Aug 2011, 12:50 AM
I am trying to set columns to IsReadOnly=true. Yet am finding that setting the value often leaves the rows editable. I can change the values in the first two rows despite "UserCanOnlyRead" being equal to true. Am I doing something wrong? None of the rows in this test project should be editable, right?

<UserControl.Resources>
    <DataTemplate x:Key="myTemplate">
        <RadioButton IsChecked="{Binding Allow, Mode=TwoWay}" />
    </DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
    <telerik:RadGridView ItemsSource="{Binding ElementName=LayoutRoot, Path=Parent.TestData}">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Allow}"
                          IsReadOnlyBinding="{Binding ElementName=LayoutRoot, Path=Parent.UserCanOnlyRead}"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Allow}"
                          CellTemplate="{Binding Source={StaticResource myTemplate}}"
                          IsReadOnly="True"/>
            <telerik:GridViewDataColumn DataMemberBinding="{Binding Allow}"
                          IsReadOnly="True"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>
</Grid>

This is the code behind:
public partial class RadGridViewDisableColumn : Page
{
    public bool UserCanOnlyRead = true;
 
    List<TestType> _testData;
    public List<TestType> TestData
    {
        get
        {
            if (_testData == null)
            {
                _testData = new List<TestType>();
                for (int i = 0; i < 10; i++)
                {
                    _testData.Add(new TestType() { Allow = i % 4 == 0 });               
                }
            }
            return _testData;
        }
    }
 
    public RadGridViewDisableColumn()
    {
        InitializeComponent();
    }
 
    public class TestType
    {
        public bool Allow { get; set; }
    }
}

1 Answer, 1 is accepted

Sort by
0
Shawn
Top achievements
Rank 1
answered on 30 Aug 2011, 02:17 AM
I went for a hack where I create two DataTemplates, where where IsEnabled="false" the other IsEnabled="true", and toggle them in the codebehind depending on the value of UserCanOnlyRead.
Tags
GridView
Asked by
Shawn
Top achievements
Rank 1
Answers by
Shawn
Top achievements
Rank 1
Share this question
or