Diable

4 posts, 0 answers
  1. haagel
    haagel avatar
    52 posts
    Member since:
    Feb 2010

    Posted 13 Aug 2010 Link to this post

    [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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 13 Aug 2010 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Uli
    Uli avatar
    33 posts
    Member since:
    Jul 2010

    Posted 23 Nov 2010 Link to this post

    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
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 24 Nov 2010 Link to this post

    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
Back to Top