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
245
WinGrid CheckBox read only?
posted

I added two unbound check boxes to my grid.

            UltraGridColumn defaultPrice = e.Layout.Bands[0].Columns.Add(DEFAULTPRICEOVERRIDE, "Override Default Pricing");
            defaultPrice.DataType = typeof(bool);
            defaultPrice.CellActivation = Activation.NoEdit;

            UltraGridColumn deleteProduct = e.Layout.Bands[0].Columns.Add(DELETEPRODUCT, "Delete Product from Grid?");
            deleteProduct.DataType = typeof(bool);
            deleteProduct.CellActivation = Activation.NoEdit;

 

I do not want the two boxes to edited unless the row is activated by a third checkbox that is bound.

I am setting the Activation to AllowEdit, however I still cannot check the boxes.  What am I missing?

       private void ugProductSelection_CellChange(object sender, CellEventArgs e)
        {
            // Get the grid.
            UltraGrid grid = (UltraGrid)sender;

            // Get the last UIElement entered.
            Infragistics.Win.UIElement lastElementEntered = grid.DisplayLayout.UIElement.LastElementEntered;
           
            // If there is no element, return.
            if (lastElementEntered == null)
                return;

            // Get the cell that the element is in.
            UltraGridCell cell = lastElementEntered.GetContext(typeof(UltraGridCell)) as UltraGridCell;

            // If there is no cell, return.
            if (cell == null)
                return;

            if (cell.Column.ToString() == PRODSELECTED)
            {
                UltraGridRow row = lastElementEntered.GetContext(typeof(UltraGridRow)) as UltraGridRow;
               
                if (cell.Text == "True")
                {
                    row.Cells[DEFAULTPRICEOVERRIDE].Activation = Activation.AllowEdit;
                    row.Cells[DELETEPRODUCT].Activation = Activation.AllowEdit;
                }
                else
                {
                    // User set the Product Selected box to unchecked, so make sure the other two
                    // boxes are unchecked.
                    row.Cells[DEFAULTPRICEOVERRIDE].Value = false;
                    row.Cells[DELETEPRODUCT].Value = false;
                    row.Cells[DEFAULTPRICEOVERRIDE].Activation = Activation.Disabled;
                    row.Cells[DELETEPRODUCT].Activation = Activation.Disabled;
                }
            }
        }

Parents
No Data
Reply
  • 37774
    posted

    I'm not sure if this will matter, but instead of going through the UIElement to get the cell, you should just be able to use e.Cell that is provided through the event args; at the very least, this will be more efficient than looking through the UIElements and the context.  You may also want to check the Key of the column instead of the ToString. 

    As to why you can't edit the cell in a particular column, I had an issue with this as well.  What's likely happening is that you're setting the CellActivation of the column to Disabled, which seems to prevent individual cells from being able to have a different activation property.  What I would do is use the InitializeRow event and manually set the Activation property of the cells based on the value of your PRODSELECTED cell, in addition to using the CellChange event; the best bet would be to refactor this logic into a helper method.  The issue I had was that the cell would appear enabled after I changed the checkbox value, but it wouldn't allow me to change the value of the newly enabled checkboxes; if you're hitting this issue, I recommend that you submit an incident with Developer Support, as it may be a bug.

    -Matt

Children
No Data