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
1025
How to AllowEdit on certain cells on a record by record basis.
posted

Is this possbile? I have a record that has a cell value that when it has a value, the record should be non-editable. If the value is null or empty, then you should be able to edit 3 of the 4 cells. Currently I assign the fieldlayouts in the AssigningFieldLayoutToItem event. I should be able to do something here right?

void theDataGrid_AssigningFieldLayoutToItem(object sender, AssigningFieldLayoutToItemEventArgs e)
        {
           
            if (((DataRowView)(e.Item)).Row["parent_id"].ToString().Length == 0)
            {
                if (theDataGrid.FieldLayouts.Exists("ParentLayout"))
                {
                    e.FieldLayout = theDataGrid.FieldLayouts["ParentLayout"];
                }
                else
                {
                    theDataGrid.FieldLayouts.Add(GetStructureFieldLayout("ParentLayout"));
                    e.FieldLayout = theDataGrid.FieldLayouts["ParentLayout"];

                    //If this item has a product_id value, then the record should not be editable.
                    //If the item does not have a product_id value, then AllowEdit on the
                    //model_id, part_id, and quantity cells.
                }
                               
            }
            else
            {
                if (theDataGrid.FieldLayouts.Exists("ChildLayout"))
                {
                    e.FieldLayout = theDataGrid.FieldLayouts["ChildLayout"];
                }
                else
                {
                    theDataGrid.FieldLayouts.Add(GetStructureFieldLayout("ChildLayout"));
                    e.FieldLayout = theDataGrid.FieldLayouts["ChildLayout"];

                    //If this item has a product_id value, then the record should not be editable.
                    //If the item does not have a product_id value, then AllowEdit on the
                    //model_id, part_id, and quantity cells.
                }
            }
        }

 

private FieldLayout GetStructureFieldLayout(string keyName)
        {
            FieldLayout fl = new FieldLayout();

            fl.Key = keyName;
            if (keyName == "ChildLayout")
                fl.Settings.LabelLocation = LabelLocation.Hidden;

            Field fld = new Field();
            fld.Name = "model_id";
            fld.Label = "Model ID";
            fld.Settings.AllowEdit = false;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "part_id";
            fld.Label = "Part ID";
            fld.Settings.AllowEdit = false;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "serial_id";
            fld.Label = "Serial ID";
            fld.Settings.AllowEdit = false;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "product_id";
            fld.Label = "Product ID";
            fld.Settings.AllowEdit = false;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "quantity";
            fld.Label = "Quantity";
            fld.Settings.AllowEdit = false;
            fl.Fields.Add(fld);

            //The following four fields are needed to show the hierarchy in the grid.
            fld = new Field();
            fld.Name = "PRODUCT_STRUCTURE_NEST";
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "product_structure_id";
            fld.Visibility = Visibility.Hidden;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "parent_id";
            fld.Visibility = Visibility.Hidden;
            fl.Fields.Add(fld);

            fld = new Field();
            fld.Name = "sequence";
            fld.Visibility = Visibility.Hidden;
            fl.Fields.Add(fld);           

            return fl;
        }

Parents
  • 8576
    Verified Answer
    Offline posted

    Hi Rod -

    I would listen to the XamDataGrid.EditModeStarting event and set EditModeStartingEventArgs.Cancel to true if you don't want the Cell to be edited.  To determine if you want to allow editing, you can look at the Cell.Value property off the event args (and potentially also the Cell.Record.Cells["otherField"].Value property if you want to take the value of other fields into account)

    Joe

Reply Children