Set read-only property for cell.

6 posts, 1 answers
  1. Anton Samarin
    Anton Samarin avatar
    29 posts
    Member since:
    Sep 2008

    Posted 26 Feb 2009 Link to this post

    Hello, 
    Can I put the property read-only only for a single cell in a row and not to the entire column?

    I want to change this value depending on the remaining cells in row.

    Thanks.
  2. Answer
    Jordan
    Admin
    Jordan avatar
    123 posts

    Posted 27 Feb 2009 Link to this post

    Hi Anton,

    You can use GridViewCell PreviewEditStartedEvent to cancel editing of some row and simulate read-only cells.

    public partial class Example 
      public Example() 
      { 
        this.InitializeComponent(); 
        this.radGridView.AddHandler(GridViewCell.PreviewEditStartEvent, new EventHandler<CellCancelRoutedEventArgs>(PreviewEditStartEventHandler)); 
      } 
             
      private void PreviewEditStartEventHandler(object sender, CellCancelRoutedEventArgs e) 
      { 
        // some custom logic 
        e.Cancel = true
      } 


    Sincerely yours,
    Jordan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WPF is Visual Studio 2017 Ready
  4. michael mccurrey
    michael mccurrey avatar
    6 posts
    Member since:
    May 2008

    Posted 06 Aug 2009 Link to this post

    Is there a way to do this via a DataTrigger via XAML?
  5. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 10 Aug 2009 Link to this post

    Hello michael mccurrey,

    Generally, IsReadOnly property can be set only on a GridViewDataColumn and RadGridView objects. Since GridViewCell do not have IsReadOnly property you cannot set this via xaml. A possible solution is to use GridViewCell.IsEnabled property in the following way:

    <Grid.Resources> 
                <Style x:Key="customCellStyle" TargetType="grid:GridViewCell"
                    <Style.Triggers> 
                        <DataTrigger Binding="{Binding IsReadOnly}" Value="True"
                            <Setter Property="IsEnabled" Value="False" /> 
                        </DataTrigger> 
                    </Style.Triggers> 
                </Style> 
            </Grid.Resources> 
            <telerik:RadGridView x:Name="radGridView" AutoGenerateColumns="False"
                <telerik:RadGridView.Columns> 
                    <telerik:GridViewDataColumn UniqueName="FirstName" CellStyle="{StaticResource customCellStyle}" /> 
                </telerik:RadGridView.Columns> 
            </telerik:RadGridView> 

    Hope this helps.

    Greetings,
    Nedyalko Nikolov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 22 Jan 2010 Link to this post

    Hello michael mccurrey,

    With the 2009.Q3 version and above you can cancel edit for a particular GridViewCell (make cell read-only for the end user) by using RadGridView.BeginningEdit event which replaced GridViewCell.PreviewEditStartEvent with a code similar to following:

    void radGridView_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
    {
       if (e.Cell.Column.UniqueName == "FirstName")
       {
           e.Cancel = true;
       }
    }


    All the best,
    Nedyalko Nikolov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  7. Ganapathi
    Ganapathi avatar
    1 posts
    Member since:
    Mar 2015

    Posted 21 Oct 2015 in reply to Nedyalko Nikolov Link to this post

    Even you can do like this..... 

     

    if (!(e.Row is GridViewRow)) return;
    var cells = (e.Row as GridViewRow).Cells.OfType<GridViewCell>();
    foreach (var cell in cells)
    {
        if (cell.Value.ToString().Equals("String"))
        {
             e.Cancel = true;
        }

    }

Back to Top
UI for WPF is Visual Studio 2017 Ready