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

[Solved] ReadOnly Rows and Cells

23 Answers 496 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tyree
Top achievements
Rank 2
Tyree asked on 12 Jul 2010, 09:20 PM
I require the ability to bind my rows to a propery which defines them as readonly and likewise the cells (not COLUMN) need to be able to be bound to a property that defines them as readonly.

I added IsRowReadOnly and IsCellReadOnly bindable properties (link) to Microsofts DataGrid but I would really like to take advantage of 1) the fact that we own Telerik controls, and 2) the features RadGridView offers. I do NOT want to have to customize the source every time you release. I do NOT want to fiddle with styles to fake it.

How can this be accomplished?

23 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 15 Jul 2010, 12:53 PM
Hi Tyree,

We will consider adding such properties, but I cannot commit with any specific date or release when these properties will be introduced.

As a workaround I could suggest you to use RadGridView.BeginningEdit event which can cancel the entire edit process. Let me know if this doesn't help.

Best wishes,
Nedyalko Nikolov
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
Tyree
Top achievements
Rank 2
answered on 15 Jul 2010, 05:11 PM
I have already considered BeginningEdit and though I can obviously change things to make this "work" we have a large enough code base that this is undesirable. We have a mechanism that prevents our VM from allowing a "property" to be changed that is ReadOnly because of various business or security reasons. By allowing the Grid to bind to these ReadOnly property it simplifies our UI. There are work-arounds but...

I most recently played with a custom column that does accomplish (in part) what we need.
public class GridViewDataColumn : GridViewBoundColumnBase
{
    /// <summary>
    /// To allow for defining the binding in XAML
    /// </summary>
    public Binding IsCellReadOnlyBinding
    {
        get;
        set;
    }
    #region Attached Property
    /// <summary>
    /// Bound property to attach to the cell
    /// </summary>
    public static readonly DependencyProperty IsCellReadOnlyProperty =
        DependencyProperty.RegisterAttached(
            "IsCellReadOnly",
            typeof(bool),
            typeof(GridViewDataColumn), null);
    public static void SetIsCellReadOnly(DependencyObject element, bool value)
    {
        element.SetValue(IsCellReadOnlyProperty, value);
    }
    public static bool GetIsCellReadOnly(DependencyObject element)
    {
        return (bool)element.GetValue(IsCellReadOnlyProperty);
    }
    #endregion
    public override FrameworkElement CreateCellEditElement(Telerik.Windows.Controls.GridView.GridViewCell cell, object dataItem)
    {
        //attach our property to the cell and set the binding
        //since the binding has no "Source" it will use the datacontext of the cell
        cell.SetBinding(GridViewDataColumn.IsCellReadOnlyProperty, IsCellReadOnlyBinding);
        var row = dataItem as ViewModel;
        if (row == null) throw new Exception("Png.GridViewDataColumn requires a bound item of base type ViewModel");
        if (row.IsReadOnly || (bool)(cell.GetValue(GridViewDataColumn.IsCellReadOnlyProperty)))
        {
            cell.IsInEditMode = false;
            return base.CreateCellElement(cell, dataItem);
        }
        return base.CreateCellEditElement(cell, dataItem);
    }
}

So in XAML
<com:GridViewDataColumn Header="Begin Date" IsCellReadOnlyBinding="{Binding EntityBeginDate.IsReadOnly}"  Width="100" IsSortable="True" MinWidth="50" DataMemberBinding="{Binding EntityBeginDate.MappedValue, Converter={StaticResource DateConverter}}">
    <com:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding EntityBeginDate.MappedValue, Converter={StaticResource DateConverter}}" Margin="4,0,4,0"/>
        </DataTemplate>
    </com:GridViewDataColumn.CellTemplate>
    <com:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <controls:DatePicker SelectedDate="{Binding EntityBeginDate.MappedValue, Converter={StaticResource DateConverter}, Mode=TwoWay}"/>
        </DataTemplate>
    </com:GridViewDataColumn.CellEditTemplate>
</com:GridViewDataColumn>

Also by moving the attached property to CreateCellElement you can check the attachedproperties value in BeginningEdit in which case you can cancel the edit but it (CreateCellElement) fires a lot more then may be needed and if I have to add custom code I prefer to keep in in one place rather then splitting them to custom column and code behind.

Any other ideas?
0
Tyree
Top achievements
Rank 2
answered on 15 Jul 2010, 07:34 PM
The template selector features would work but would require me to have two templates for every column if I understand it correctly.
0
Nedyalko Nikolov
Telerik team
answered on 16 Jul 2010, 04:09 PM
Hi Tyree,

Indeed you are right with Template selector feature you will need two templates.

Unfortunately with the current version of the grid I cannot suggest you a better solution than using RadGridView.BeginningEdit event. As I said we will consider adding such functionality to RadGridView control.

Regards,
Nedyalko Nikolov
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
Tyree
Top achievements
Rank 2
answered on 16 Jul 2010, 06:09 PM
There are problems using the Selector also.

My current solution, which is working fine, is to create a custom column for each telerik column (using the corresponding telerik column as its base) and add an IsCellReadOnlyBinding property to the column. Then in the Beginning edit I pull this Binding and bind it to an attached property of GridViewCell and then GetValue on that attached property to determine if I should cancel. The only problem is it wont respond to any changes to that bound property but I am ok with this limitation.

I look forward to a built in mechanism :)
0
Milan
Telerik team
answered on 19 Jul 2010, 08:03 AM
Hi Tyree,

Thank you for your valuable feedback. I hope that we will be able to introduce the mentioned improvements as soon as possible. 


Sincerely yours,
Milan
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
Nedyalko Nikolov
Telerik team
answered on 01 Sep 2010, 02:04 PM
Hi Tyree,

Take a look at the attached example. It demonstrates a new property called IsReadOnlyBinding which can be set on a column or on a grid level.
The example demonstrates how second row ("Doe 1") is read only except the "Age" cell (which has its own IsReadOnlyBinding).
Let me know how example works on your end.

Greetings,
Nedyalko Nikolov
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
Tyree
Top achievements
Rank 2
answered on 01 Sep 2010, 03:26 PM
I expanded the example a bit and have two thoughts on its current implementation.

1) I expected that row readonly would override the cell. Meaning if I want to stop the whole row from being edited I would not expect a cell's readonly property to take precedence. My personal implementation only checks the cell if the row is editable.

In our application each "property" which is editable has additional properties that regulate whether its readonly and its validation. Then again the the row level we have a readonly property. So either through UI or code behind if you try to set one of those properties it checks if the row is editable, if so it checks if that property is editable, if so it edits and performs validation.

2) This isn't as important as #1. If a cell is in edit mode, and the IsReadOnlyBinding property changes I would expect the cell to cancel its edit and leave edit mode. Likewise with the row level, if at row level goes readonly and the row is being edited, cancel the edit and return to view mode. This is how I had the microsoft grid working but it rarely was used. The only case we had in which this was triggered was if security permissions changed in mid-edit which is not common.

It is very nice to see your progress so quickly.
0
Nedyalko Nikolov
Telerik team
answered on 02 Sep 2010, 09:28 AM
Hi Tyree,

Straight onto your questions (thoughts):

1. You expect that row should take precedence over cell value, but I cannot agree with that. Anywhere in xaml technologies the closer setter takes precedence. For example if you set TextBlock.Background and its parent Border.Background which background will be applied on the textblock?

2. We will consider adding almost same functionality. By almost same I mean that we could add check to IsReadOnlyBinding value on Cell.CommitEdit procedure and take the appropriate actions there.

Thank you for valuable feedback.

Regards,
Nedyalko Nikolov
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
Tyree
Top achievements
Rank 2
answered on 02 Sep 2010, 02:38 PM
I don't believe its fair to compare IsReadOnly functionality to the visual property 'background'. If you were to compare it to a visual property I would compare it to Visibility. If you set a parent to Collapsed, the childs Visibility is irrellavent. Container over contained. No one would expect a childs Visibility to thwart the parents.

If we have a Row.IsReadOnly that has no control over the cells (if they also define isreadonlybinding) then it is argueably almost useless when we could simply bind each column.isreadonlybinding to the same value as the row.isreadonly - you have simply reduced the number of definitions needed. By allowing for an order of precedence I believe it offers the user more functionality then simply reducing the number of definitions.
0
Nedyalko Nikolov
Telerik team
answered on 06 Sep 2010, 09:12 PM
Hello Tyree,

We reconsidered our vision about "IsReadOnlyBinding property" precedence. You can download our latest internal build and check how it goes on your end along with my apologies for the inaccurate comparison.
Thank you for your valuable feedback.

Best wishes,
Nedyalko Nikolov
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
Tyree
Top achievements
Rank 2
answered on 08 Sep 2010, 03:11 PM
Thank you for reconsidering and no apology necessary. Its just good to feel heard.

So I tried your latest build and it has worked so well that I have removed all my changes and have incorporated your latest build in our production bound build. It has passed our internal tests and allowed us to simplify our templates now that the features are built in! Thank you very much and I look forward to your next full release!
0
Nedyalko Nikolov
Telerik team
answered on 13 Sep 2010, 02:58 PM
Hello Tyree,

I'm glad that everything is working fine on your end.
The official release (a.k.a 2010.Q2.SP2) will be released in a week or two.

Sincerely yours,
Nedyalko Nikolov
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
Aaron Hanusa
Top achievements
Rank 1
answered on 23 Sep 2010, 08:30 PM
I'm looking to utilize the IsReadOnlyBinding property.  When will this be released?
0
Nedyalko Nikolov
Telerik team
answered on 28 Sep 2010, 08:21 AM
Hi Aaron Hanusa,

You can download service pack 2 (2010.Q2.SP2) from your Telerik account (IsReadOnlyBinding property is included). 

Best wishes,
Nedyalko Nikolov
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
Steve
Top achievements
Rank 1
answered on 08 Oct 2010, 06:59 AM
In the example project, it has
    xmlns:local="clr-namespace:IsReadOnlyBindingExample"
I added this to my xaml and it isn't found. Please advise. I am using v.2010.2.924.1040 Trial 
0
Vlad
Telerik team
answered on 08 Oct 2010, 07:34 AM
Hi,

If you do not have such namespace in your project you cannot expect this to work. 

Regards,
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
Steve
Top achievements
Rank 1
answered on 08 Oct 2010, 07:55 AM
Thanks for that. I was rather hoping you might gve me a hint as to how to add it - i.e. do I have to add a reference to the project, and in which case which one?
0
Steve
Top achievements
Rank 1
answered on 08 Oct 2010, 07:59 AM
Or better still, tell me how to use IsReadOnlyBinding without using that namespace! Perhaps someone could convert the example project to use Q2 2010?
0
Vlad
Telerik team
answered on 08 Oct 2010, 08:02 AM
Hello,

 This is namespace declaration to the local application namespace. In case of our example this was IsReadOnlyBindingExample. When you have such declaration in your XAML you will be able to declare classes from this namespace. 

Regards,
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
Steve
Top achievements
Rank 1
answered on 08 Oct 2010, 08:13 AM
OK, let me ask the question another way. How do I use the new feature on Q2 2010 called IsReadOnlyBinding? I downloaded Nedyalko's example, which appears to work correctly, but clearly it uses something not included in the standard release, so I cannot implement the feature in my project.
0
Nedyalko Nikolov
Telerik team
answered on 13 Oct 2010, 08:08 AM
Hi Steve,

I've just tested the example with 2010.Q2.SP2 binaries and everything works fine on my end. According to xmlns:local="clr-namespace:IsReadOnlyBindingExample" namespace declaration this is just a reference to the example project which uses a custom value converter. In order to use IsReadOnlyBinding feature of the RadGridView you don't need this namespace declaration.
I hope this makes sense.

Best wishes,
Nedyalko Nikolov
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
Steve
Top achievements
Rank 1
answered on 13 Oct 2010, 10:57 AM
Thanks for getting back to me, Nedyalko.

All is fine now - I was trying to follow the example, but in fact I found I just needed to put IsReadOnlyBinding on the GridViewDataColumn definitions. No need for the readonly converter etc.
Tags
GridView
Asked by
Tyree
Top achievements
Rank 2
Answers by
Nedyalko Nikolov
Telerik team
Tyree
Top achievements
Rank 2
Milan
Telerik team
Aaron Hanusa
Top achievements
Rank 1
Steve
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or