Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
745
Make cell read only
posted

Hi guys!

How can I make a single cell read only, preferably by using data binding, but doing it "manually" in code is also ok.
I do not want the entire column to be read only, I just need some of the cells in the column to be read only.

What I'm trying to do, is bind a collection of objects to a grid (which works just fine), and the objects has properties which can be used to determine if some property should be read only or not...

-Thanks!

Parents
No Data
Reply
  • 745
    posted

    Found one solution myself, although I think it's not as elegant as I would like, but it works;

    By subscribing to the CellActivating event for the XamDataGrid, I can cancel the activation making the cell read only.

    this.xamDataGrid_factDefinition.CellActivating += new EventHandler<CellActivatingEventArgs>(xamDataGrid_factDefinition_CellActivating);

    ...

    void xamDataGrid_factDefinition_CellActivating(object sender, CellActivatingEventArgs e)
    {
         if (e.Cell.Field.Name == "Standard")
         {     
             FactDefinitionUIWrapperEntity
    wrapperEntity = e.Cell.Record.DataItem as FactDefinitionUIWrapperEntity;
            
    if (wrapperEntity != null)
             {
                   e.Cancel = !wrapperEntity.IsStandardEditable;
             }
         }
        
    else if (e.Cell.Field.Name == "Mandatory")
         {
             
    FactDefinitionUIWrapperEntity wrapperEntity = e.Cell.Record.DataItem as FactDefinitionUIWrapperEntity;
             
    if (wrapperEntity != null)
             
    {
                    e.Cancel = !wrapperEntity.IsMandatoryEditable;
              }
         }
    }
Children