コード例 #1
0
        /// <summary>
        /// Start editing the cell passed. Do not call this method for start editing a cell, you must use Cell.StartEdit.
        /// </summary>
        /// <param name="p_Cell">Cell to start edit</param>
        /// <param name="position">Editing position(Row/Col)</param>
        /// <param name="p_StartEditValue">Can be null(in this case use the p_cell.Value</param>
        public override void InternalStartEdit(Cells.ICellVirtual p_Cell, Position position, object p_StartEditValue)
        {
            base.InternalStartEdit(p_Cell, position, p_StartEditValue);

            if (EnableEdit == false)
            {
                return;
            }

            ComboBoxTyped l_Combo = GetEditorComboBox(p_Cell.Grid);

            l_Combo.Validator              = this;
            l_Combo.EnableEscapeKeyUndo    = false;
            l_Combo.EnableEnterKeyValidate = false;
            l_Combo.EnableLastValidValue   = false;
            l_Combo.EnableAutoValidation   = false;

            if (p_StartEditValue is string && IsStringConversionSupported())
            {
                l_Combo.TextBox.Text = TextBoxTyped.ValidateCharactersString((string)p_StartEditValue, l_Combo.TextBox.ValidCharacters, l_Combo.TextBox.InvalidCharacters);
                if (l_Combo.TextBox.Text != null)
                {
                    l_Combo.TextBox.SelectionStart = l_Combo.TextBox.Text.Length;
                }
                else
                {
                    l_Combo.TextBox.SelectionStart = 0;
                }
            }
            else
            {
                l_Combo.Value = p_Cell.GetValue(position);
                l_Combo.SelectAllTextBox();
            }
        }
コード例 #2
0
        /// <summary>
        /// Change the value of the cell applying the rule of the current editor.
        /// Is recommend to use this method to simulate a edit operation and to validate
        /// the cell value using the current model.
        /// </summary>
        /// <param name="p_Cell">Cell to change value</param>
        /// <param name="position">Current Cell Position</param>
        /// <param name="p_NewValue">New value</param>
        /// <returns>
        /// returns true if the value passed is valid and has been applied to the cell
        /// </returns>
        public virtual bool SetCellValue(Cells.ICellVirtual p_Cell, Position position, object p_NewValue)
        {
            if (EnableEdit == false)
            {
                return(false);
            }

            CellValidatingEventArgs l_cancelEvent = new CellValidatingEventArgs(p_Cell, p_NewValue);

            OnValidating(l_cancelEvent);

            // check whether cancel == true
            if (l_cancelEvent.Cancel == false)
            {
                object l_PrevValue = p_Cell.GetValue(position);
                try
                {
                    p_Cell.SetValue(position, ObjectToValue(l_cancelEvent.NewValue));
                    OnValidated(new CellValidatedEventArgs(p_Cell));
                }
                catch (Exception ex)
                {
                    LoggerManager.Log(LogLevels.Warning, "Exception caught: " + ex.ToString());
                    p_Cell.SetValue(position, l_PrevValue);
                    l_cancelEvent.Cancel = true;
                }
            }

            return(l_cancelEvent.Cancel == false);
        }
コード例 #3
0
        /// <summary>
        /// Change the value of the cell applying the rule of the current editor. Is recommend to use this method to simulate a edit operation and to validate the cell value using the current model.
        /// </summary>
        /// <param name="p_Cell">Cell to change value</param>
        /// <param name="p_Position">Current Cell Position</param>
        /// <param name="p_NewValue"></param>
        /// <returns>returns true if the value passed is valid and has been applied to the cell</returns>
        public virtual bool SetCellValue(Cells.ICellVirtual p_Cell, Position p_Position, object p_NewValue)
        {
            if (EnableEdit)
            {
                ValidatingCellEventArgs l_cancelEvent = new ValidatingCellEventArgs(p_Cell, p_NewValue);
                OnValidating(l_cancelEvent);

                //check if cancel == true
                if (l_cancelEvent.Cancel == false)
                {
                    object l_PrevValue = p_Cell.GetValue(p_Position);
                    try
                    {
                        p_Cell.SetValue(p_Position, ObjectToValue(l_cancelEvent.NewValue));
                        OnValidated(new CellEventArgs(p_Cell));
                    }
                    catch (Exception)
                    {
                        p_Cell.SetValue(p_Position, l_PrevValue);
                        //throw err;
                        l_cancelEvent.Cancel = true;                        //di fatto � fallita la validazione del dato
                    }
                }

                return(l_cancelEvent.Cancel == false);
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        /// <summary>
        /// Start editing the cell passed
        /// </summary>
        /// <param name="p_Cell">Cell to start edit</param>
        /// <param name="p_Position">Editing position(Row/Col)</param>
        /// <param name="p_StartEditValue">Can be null(in this case use the p_cell.Value</param>
        public override void InternalStartEdit(Cells.ICellVirtual p_Cell, Position p_Position, object p_StartEditValue)
        {
            base.InternalStartEdit(p_Cell, p_Position, p_StartEditValue);

            if (EnableEdit == false)
            {
                return;
            }

            DateTimePicker l_DtPicker = GetEditorDateTimePicker(p_Cell.Grid);

            if (p_StartEditValue != null)
            {
                if (p_StartEditValue is DateTime)
                {
                    l_DtPicker.Value = (DateTime)p_StartEditValue;
                }
                else if (p_StartEditValue == null)
                {
                    l_DtPicker.Value = DateTime.Now;
                }
                else
                {
                    throw new SourceGridException("Invalid StartEditValue, expected DateTime");
                }
            }
            else
            {
                object l_Val = p_Cell.GetValue(p_Position);
                if (l_Val is DateTime)
                {
                    l_DtPicker.Value = (DateTime)l_Val;
                }
                else if (l_Val == null)
                {
                    l_DtPicker.Value = DateTime.Now;
                }
                else
                {
                    throw new SourceGridException("Invalid cell value, expected DateTime");
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Start editing the cell passed. Do not call this method for start editing a cell, you must use Cell.StartEdit.
        /// </summary>
        /// <param name="p_Cell">Cell to start edit</param>
        /// <param name="p_Position">Editing position(Row/Col)</param>
        /// <param name="p_StartEditValue">Can be null(in this case use the p_cell.Value</param>
        public override void InternalStartEdit(Cells.ICellVirtual p_Cell, Position p_Position, object p_StartEditValue)
        {
            base.InternalStartEdit(p_Cell, p_Position, p_StartEditValue);

            if (EnableEdit == false)
            {
                return;
            }

            SourceLibrary.Windows.Forms.TextBoxTyped l_TxtBox = GetEditorTextBox(p_Cell.Grid);

            l_TxtBox.Validator              = this;
            l_TxtBox.EnableEscapeKeyUndo    = false;
            l_TxtBox.EnableEnterKeyValidate = false;
            l_TxtBox.EnableLastValidValue   = false;
            l_TxtBox.EnableAutoValidation   = false;

            l_TxtBox.Multiline = m_bMultiLine;
            if (m_bMultiLine == false)
            {
                l_TxtBox.MaxLength = m_MaxLength;
            }

            l_TxtBox.WordWrap          = p_Cell.VisualModel.WordWrap;
            l_TxtBox.TextAlign         = Utility.ContentToHorizontalAlignment(p_Cell.VisualModel.TextAlignment);
            l_TxtBox.Font              = p_Cell.VisualModel.Font;
            l_TxtBox.ValidCharacters   = m_ValidCharacters;
            l_TxtBox.InvalidCharacters = m_InvalidCharacters;

            //if (p_StartEditValue!=null && IsStringConversionSupported())
            if (p_StartEditValue is string && IsStringConversionSupported())
            {
                l_TxtBox.Text           = SourceLibrary.Windows.Forms.TextBoxTyped.ValidateCharactersString((string)p_StartEditValue, m_ValidCharacters, m_InvalidCharacters);
                l_TxtBox.SelectionStart = l_TxtBox.Text.Length;
            }
            else
            {
                l_TxtBox.Value = p_Cell.GetValue(p_Position);
                l_TxtBox.SelectAll();
            }
        }
コード例 #6
0
        /// <summary>
        /// Start editing the cell passed
        /// </summary>
        /// <param name="p_Cell">Cell to start edit</param>
        /// <param name="p_Position">Editing position(Row/Col)</param>
        /// <param name="p_StartEditValue">Can be null(in this case use the p_cell.Value</param>
        public override void InternalStartEdit(Cells.ICellVirtual p_Cell, Position p_Position, object p_StartEditValue)
        {
            base.InternalStartEdit(p_Cell, p_Position, p_StartEditValue);

            if (EnableEdit == false)
            {
                return;
            }

            System.Windows.Forms.NumericUpDown l_Control = GetEditorNumericUpDown(p_Cell.Grid);

            l_Control.Maximum   = m_Maximum;
            l_Control.Minimum   = m_Minimum;
            l_Control.Increment = m_Increment;

            if (p_StartEditValue != null)
            {
                SetValueToControl(p_StartEditValue);
            }
            else
            {
                SetValueToControl(p_Cell.GetValue(p_Position));
            }
        }