Exemple #1
0
        /// <summary>
        /// Toggle the value of the current cell and if AutoChangeValueOfSelectedCells is true of all the selected cells.
        /// Simulate an edit operation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UIChangeChecked(CellContext sender, EventArgs e)
        {
            Models.ICheckBox checkModel = (Models.ICheckBox)sender.Cell.Model.FindModel(typeof(Models.ICheckBox));;
            if (checkModel == null)
            {
                throw new SourceGrid.SourceGridException("Models.ICheckBox not found");
            }

            Models.CheckBoxStatus checkStatus = checkModel.GetCheckBoxStatus(sender);
            if (checkStatus.CheckEnable)
            {
                bool newVal = true;
                if (checkStatus.Checked != null)
                {
                    newVal = !checkStatus.Checked.Value;
                }

                sender.StartEdit();
                try
                {
                    checkModel.SetCheckedValue(sender, newVal);
                    sender.EndEdit(false);
                }
                catch (Exception)
                {
                    sender.EndEdit(true);
                    throw;
                }

                //change the status of all selected control
                if (AutoChangeValueOfSelectedCells)
                {
                    foreach (Position pos in sender.Grid.Selection.GetSelectionRegion().GetCellsPositions())
                    {
                        Cells.ICellVirtual c = sender.Grid.GetCell(pos);
                        Models.ICheckBox   check;
                        if (c != this && c != null &&
                            (check = (Models.ICheckBox)c.Model.FindModel(typeof(Models.ICheckBox))) != null)
                        {
                            CellContext context = new CellContext(sender.Grid, pos, c);
                            context.StartEdit();
                            try
                            {
                                check.SetCheckedValue(context, newVal);
                                context.EndEdit(false);
                            }
                            catch (Exception)
                            {
                                context.EndEdit(true);
                                throw;
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Toggle the value of the current cell and if AutoChangeValueOfSelectedCells is true of all the selected cells.
        /// Simulate an edit operation.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void UIChangeChecked(CellContext sender, EventArgs e)
        {
            Models.ICheckBox checkModel = (Models.ICheckBox)sender.Cell.Model.FindModel(typeof(Models.ICheckBox));;
            if (checkModel == null)
            {
                throw new SourceGrid.SourceGridException("Models.ICheckBox not found");
            }

            Models.CheckBoxStatus checkStatus = checkModel.GetCheckBoxStatus(sender);
            if (checkStatus.CheckEnable)
            {
                bool newVal = true;
                if (checkStatus.Checked != null)
                {
                    newVal = !checkStatus.Checked.Value;
                }

                if (sender.StartEdit())
                {
                    try
                    {
                        checkModel.SetCheckedValue(sender, newVal);
                        sender.EndEdit(false);
                        OnCheckedChanged(EventArgs.Empty);
                    }
                    catch (Exception ex)
                    {
                        sender.EndEdit(true);
                        throw new Exception(string.Empty, ex);
                    }

                    //change the status of all selected control
                    if (AutoChangeValueOfSelectedCells)
                    {
                        AutoChangeValues(sender, newVal);
                    }
                }
            }
        }