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

Diable

3 Answers 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
haagel
Top achievements
Rank 1
haagel asked on 13 Aug 2010, 08:24 AM
[Note to Telerik: I messed the title up! Could you change it to "Enable/Disable editing of cell for individual rows"]

I have a GridView where some of the columns are editable and some are readonly. But now I also have some columns that should be editable for some rows but not for others.

The GridView is bound to a list of items. These items are of a custom type/class that has properties for each column of the GridView. The class also has a property which tells if those columns (that are sometimes editable) should be editable or not.

How can I make this work?

I specify the columns of the grid manually with XAML. The columns have a CellTemplate (usually with a TextBlock), and those that can be edited also has a CellEditTemplate (usually with a TextBox). The switching between those works fine, but sometimes I don't want that switch to happen. That is, even if the user clicks the cell to edit it, the cell shouldn't switch over to edit mode (using CellEditTemplate) if that cell is not editable for that particular row.

Some code to illustrate my situation
<telerikGridView:GridViewDataColumn Header="Age" DataMemberBinding="{Binding Path=Age}">
    <telerikGridView:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding Path=Age, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </telerikGridView:GridViewDataColumn.CellTemplate>
    <telerikGridView:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <TextBox Text="{Binding Path=Age, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
        </DataTemplate>
    </telerikGridView:GridViewDataColumn.CellEditTemplate>
</telerikGridView:GridViewDataColumn>

public class Person
{
    public int Age { get; set; }
    public bool ThisRowIsFullyEditable { get; set; }
}

So.. can I by using the "ThisRowIsFullyEditable" property make the column Age editable or not for each row individually?

Thanks // David

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 13 Aug 2010, 08:49 AM
Hello David Haglund,

You can handle the BeginningEdit event of the grid and cancel editing for the rows meeting the requirement for being not-fully-editable. For example:

void personsGrid_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
{
    Person person = e.Row.Item as Person;
    if(!person.ThisRowIsFullyEditable)
    {
        e.Cancel = true;
    }
}


Greetings,
Maya
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
Uli
Top achievements
Rank 1
answered on 23 Nov 2010, 06:11 PM
If I want to step through the cells with the tab key, cancelling the BeginningEdit event causes to leave the edit mode. Is there a way to achieve the same behaviour as I have when I make a whole column read only? That is if a single cell is not editable it is just omitted in the tab sequence.

Regards Uli
0
Maya
Telerik team
answered on 24 Nov 2010, 08:56 AM
Hello Uli,

Now RadGridView exposes a IsReadOnlyBinding property and you may give it a try. For further reference please take a look at this article on the topic.
 

Sincerely yours,
Maya
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
GridView
Asked by
haagel
Top achievements
Rank 1
Answers by
Maya
Telerik team
Uli
Top achievements
Rank 1
Share this question
or