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
35
How to disable addition of child rows when the child row summation exceeds parent row cell value
posted

Hello,

I have a grid with two bands (dataset) that allows users to add child rows beneath a parent row. I have specified one of the child row columns as a summation.  How can I restrict users from adding new child rows when the child row summation exceeds the value of a  specified cell in the parent row? 

Thanks

Parents
No Data
Reply
  • 1560
    Offline posted

    Hello,

    I have been looking into your question and created a small sample in order to demonstrate how such behavior could be achieved.

    If you click to add a new row, the InitializeRow and AfterRowActivated events would be fired and the row's IsAddRow would be true. In order to check whether the current children sum is less than the parent sum, I'm using the isAllowedAdding method and as a parameter, I pass the row we want to add. If the method returns false and the row could not be added I set the row's Activation property to disabled, so the cells could not be edited. However, after the InitializeRow event, the AfterRowActivated event would be fired and the row would be marked as active in the grid. In order to prevent that I'm using a global variable that would indicate if the active row is a new one that should not be added.  In the AfterRowActivated event handler after checking this global variable value if we are trying to add new row but the adding is not valid, we can set the grid's ActiveRow property to null. This way the row would not be marked if the adding is not allowed. 

    bool _canActivate = false;
            private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
            {
                //…
                if (e.Row.IsAddRow && !isAllowedAdding(e.Row))
                {              
                    e.Row.Activation = Activation.Disabled;
                    _canActivate = true;
                }
            }
    private void ultraGrid1_AfterRowActivate(object sender, EventArgs e)
            {
                if (_canActivate)
                {
                    (sender as UltraGrid).ActiveRow = null;
                }
                _canActivate = false;
     
            }

    Attached you will find my sample for your reference. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach it in this case.

    Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.

    Thank you for your cooperation.

    Looking forward to hearing from you.

    Sincerely,

    Teodosia Hristodorova

    Associate Software Developer

    6622.UltraGrid_disable_adding_row_condition.zip

Children
No Data