Welcome to the Xceed Community | Help
Community Search  
More Search Options

DataCell ReadOnly="True" do not disables entering to edit mode

Sort Posts: Previous Next
  •  11-30-2011, 2:37 AM Post no. 31382

    DataCell ReadOnly="True" do not disables entering to edit mode

    I need to have some Cells in grid to be ReadOnly and some to be editable. I have found that settings property ReadOnly="True" for DataCell has no influance, and there is still posiible to edit content of cell (for test I use default editor). I use Style like this
    <Style TargetType="{x:Type xcdg:DataCell}">

    <Setter Property="ReadOnly" Value="True" />
    <Style.Triggers>
    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ReadOnly}" Value="True">
    <Setter Property="Background" Value="Red" />
    </DataTrigger>
    </Style.Triggers>

    </Style>

     to set ReadOnly for all DataCells (just for test purposes), but only background color changes to red (to confim that ReadOnly is true), but there is still possible to open cell editor and edit value in cell. It looks that only Column ReadOnly can disable editing (but for whole columnSad as expected) or DataGridControl.

    What I'm doing wrong?

  •  11-30-2011, 10:03 AM Post no. 31389 in reply to 31382

    Re: DataCell ReadOnly="True" do not disables entering to edit mode

    Hi Daniel

    This is how your style should look like assuming you have a "ReadOnly" column that you want to be readonly whenever the underlying value is true: 

          <Style TargetType="{x:Type xcdg:DataCell}">

             <Style.Triggers>

                <DataTrigger Binding="{Binding RelativeSource={RelativeSource self}, 

                                                                Path=ParentRow.DataContext.ReadOnly}"

                                  Value="True">

                   <Setter Property="ReadOnly" Value="True"/>

                </DataTrigger>

                

             </Style.Triggers>

             

          </Style> 

     

    You can find more information and a few samples on data cell styling in the following blog post :

    http://xceed.com/CS/blogs/techside/archive/2011/07/06/datacell-styling-vs-cellcontenttemplate.aspx 


    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  12-01-2011, 2:43 AM Post no. 31393 in reply to 31389

    Re: DataCell ReadOnly="True" do not disables entering to edit mode

    Hi Michel,

    my problem is that even though I set DataCell property ReadOnly="True" there is possible to activate CellEditor for that Cell.
    My situation is following:
    I have grid with columns A,B,C,D and rows 0,1,2. I need to have editable cells in column B, C, D, but not cells B1, B2, C0.
    How to achieve that?
    When I set DataCell property ReadOnly="True" for Cells B1, B2, C0, and for Column B,C,D ReadOnly="False"
    (because I need to have other cells of column to be editable), I can still edit (activate CellEditor by gestures) "ReadOnly" cells.

    Actually I see only solution in use of my own DataTemplate for CellEditor with TextBox and setting ReadOnly property of that TextBox,
    so CellEditor will display for all cells in column, but for ReadOnly cells there would not be possible to modify shown value in cell editor.
    I don't know how to disable possibility to activate CellEditor in singles DataCells. 

    Filed under: ,
  •  12-01-2011, 2:09 PM Post no. 31394 in reply to 31393

    Re: DataCell ReadOnly="True" do not disables entering to edit mode

    Hi Daniel, 

    Did you check the sample in the blog post? When the Readonly property is set to true, the cell does not enter in edit mode.

     

    If you are still having problems, could you send us your sample application so that we investigate it in more detail and provide you with a better answer?

     

    You can send it to support@xceed.com Please include a reference to this forum post in your email.  


    Best Regards,

    Michel Dahdah
    Technical Support
    Xceed Software inc.
  •  12-02-2011, 4:26 AM Post no. 31395 in reply to 31394

    Re: DataCell ReadOnly="True" do not disables entering to edit mode

    Hi Michael,

    finally I solve it, thank you. Use of MultiDataTrigger in DataCell style was solution. Now it works as expected. Here is that style when somebody needs similar functionality:

    <!--force readonly of cell when its data are not editable-->

    <Style TargetType="{x:Type xcdg:DataCell}">

    <Style.Triggers>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <Condition Binding="{Binding RelativeSource={RelativeSource self}, Path=ParentColumn.FieldName}"

    Value="ColumnB"/>

    <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataRow},AncestorLevel=1},

    Path=DataContext.ColumnB.IsReadOnly}"

    Value="True"/>

    </MultiDataTrigger.Conditions>

    <Setter Property="ReadOnly" Value="True" />

    </MultiDataTrigger>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <Condition Binding="{Binding RelativeSource={RelativeSource self}, Path=ParentColumn.FieldName}"

    Value="ColumnC"/>

    <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataRow},AncestorLevel=1},

    Path=DataContext.ColumnC.IsReadOnly}"

    Value="True"/>

    </MultiDataTrigger.Conditions>

    <Setter Property="ReadOnly" Value="True" />

    </MultiDataTrigger>

    <MultiDataTrigger>

    <MultiDataTrigger.Conditions>

    <Condition Binding="{Binding RelativeSource={RelativeSource self}, Path=ParentColumn.FieldName}"

    Value="ColumnD"/>

    <Condition Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:DataRow},AncestorLevel=1},

    Path=DataContext.ColumnD.IsReadOnly}"

    Value="True"/>

    </MultiDataTrigger.Conditions>

    <Setter Property="ReadOnly" Value="True" />

    </MultiDataTrigger>

    <!-- when cell belongs to editable column but is readOnly, change its backgoround to red-->

    <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ReadOnly}" Value="True">

    <Setter Property="Background" Value="#15FF0000" />

    </DataTrigger>

    </Style.Triggers>

    </Style>

View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2011 Xceed Software Inc.