modifying a file?

Ok total newbie alert.

I copied this code and it works generally fine.

The problem is when I type data into the textbox it never enables the OK button (its always greyed out)

Anyone any pointers as to what to do?

Thanks
Paul




namespace SchemaSetPlugin.Design
{
    public partial class StringDataTypePropertyPage2 : PropertyPage
    {
        private TextBox _oOptionTextBox;
        private CheckBox _oBlankCheckBox;
        private CheckBox _oOptionCheckBox;
        private Label label4;
        private Label label3;
        private Label label1;
        private Label label6;
        private Label label5;
        private string _oInitialValue;
        PropertiesDialog _oPropertiesDialog;
        StringDataType _oStringDataType;

        public StringDataTypePropertyPage2(PropertiesDialog oPropertiesDialog, StringDataType oStringDataType)
            : base(oPropertiesDialog)
        {
            InitializeComponent();
            _oPropertiesDialog = oPropertiesDialog;
            _oStringDataType = oStringDataType;

            if (((string)_oStringDataType.InitialValue == "") || (_oStringDataType.InitialValue == null))
            //if the initial value is blank in the XML
            {
                _oBlankCheckBox.Checked = true;
                _oOptionCheckBox.Checked = false;
                _oOptionTextBox.Enabled = false;
            }
            else
            {
                //_oOptionTextBox.Text = _oInitialValue.ToString();
                _oBlankCheckBox.Checked = false;
                _oOptionCheckBox.Checked = true;
                _oOptionTextBox.Enabled = true;

                //only do this here as if done above will create an initial value when its not in the XML
                _oInitialValue = _oStringDataType.InitialValue.ToString();
                _oOptionTextBox.Text = _oInitialValue.ToString();

            }



        }

        public override void OnApply()
        {
            if (_oBlankCheckBox.Checked)
            {
                _oStringDataType.InitialValue = null;
            }
            else
            {
                _oStringDataType.InitialValue = _oInitialValue;
            }
            // save the project
            // TODO: this is stupid. should just be able to CurrentProject.Save()
            VSAB.Builder.IGui.Designer.FindDesigner(VSAB.Builder.IGui.IGuiPluginInterface.Instance.CurrentProject.GetType()).SaveToFile(VSAB.Builder.IGui.IGuiPluginInterface.Instance.CurrentProject);
        }

        public override bool CanApply()
        {
            if (_oBlankCheckBox.Checked)
            {
                //needed?
                //_oInitialValue = new decimal();
                return true;
            }
            else
            //it has an initial value
            {
                //if its blank there will be an error when converting
                if (_oOptionTextBox.Text.Trim() == "")
                {
                    _oInitialValue = "";
                }
                else
                {
                    _oInitialValue = _oOptionTextBox.Text.Trim().ToString();
                }




                return AllowNext(true);
            }
        }

        public override string TabText
        {
            get { return "Defaults"; }
        }

        private bool AllowNext(bool bShowDialogs)
        {
            if (((DataTypePropertiesDialog)_oPropertiesDialog).CustomDataTypePropertyPage.List.Count > 0)
            {
                int[] iInfoArray = new int[((DataTypePropertiesDialog)_oPropertiesDialog).CustomDataTypePropertyPage.List.Count];
                ((DataTypePropertiesDialog)_oPropertiesDialog).CustomDataTypePropertyPage.List.CopyTo(iInfoArray);

                if (!IsNumeric(_oOptionTextBox.Text.Trim()) || _oOptionTextBox.Text.Trim().EndsWith("."))
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("Please enter a valid number.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                double dDefaultNumber = double.Parse(_oOptionTextBox.Text);
                if (iInfoArray[0] == 1 && dDefaultNumber < iInfoArray[1])
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("Default number must be more than or equal to the min value entered in the previous screen.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                if (iInfoArray[2] == 1 && dDefaultNumber > iInfoArray[3])
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("Default number must be less than or equal to the max value entered in the previous screen.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                string[] sDefaultNumber = _oOptionTextBox.Text.Trim().Split('.');

                if (sDefaultNumber[0].Length > iInfoArray[4])
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("The default decimal number entered does not correspond to the Digits Before DP or Digits After DP in the previous screen.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                if (sDefaultNumber.Length == 2 && sDefaultNumber[1].Length > iInfoArray[5])
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("The default decimal number entered does not correspond to the Digits Before DP or Digits After DP in the previous screen.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                if (sDefaultNumber.Length == 2 && iInfoArray[5] == 0)
                {
                    if (bShowDialogs)
                    {
                        MessageBox.Show("The default decimal number entered does not correspond to the Digits Before DP or Digits After DP in the previous screen.", "Invalid Number", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    //_oOptionTextBox.SelectAll();
                    //_oOptionTextBox.Focus();
                    return false;
                }

                //_oInitialValue = Convert.ToDecimal(_oOptionTextBox.Text.Trim());
                return true;

            }
            return false;
        }

        private bool IsNumeric(object oValueToCheck)
        {
            double dDummy = new double();
            string sInputValue = Convert.ToString(oValueToCheck);

            bool bNumeric = double.TryParse(sInputValue, System.Globalization.NumberStyles.Any, null, out dDummy);

            return bNumeric;
        }


        private void InitializeComponent()
        {
            this._oOptionTextBox = new System.Windows.Forms.TextBox();
            this._oBlankCheckBox = new System.Windows.Forms.CheckBox();
            this._oOptionCheckBox = new System.Windows.Forms.CheckBox();
            this.label4 = new System.Windows.Forms.Label();
            this.label3 = new System.Windows.Forms.Label();
            this.label1 = new System.Windows.Forms.Label();
            this.label6 = new System.Windows.Forms.Label();
            this.label5 = new System.Windows.Forms.Label();
            this.SuspendLayout();
            //
            // _oOptionTextBox
            //
            this._oOptionTextBox.Location = new System.Drawing.Point(158, 175);
            this._oOptionTextBox.Name = "_oOptionTextBox";
            this._oOptionTextBox.Size = new System.Drawing.Size(100, 20);
            this._oOptionTextBox.TabIndex = 47;
            this._oOptionTextBox.TextChanged += new System.EventHandler(this._oOptionTextBox_TextChanged);
            //
            // _oBlankCheckBox
            //
            this._oBlankCheckBox.AutoSize = true;
            this._oBlankCheckBox.Location = new System.Drawing.Point(302, 144);
            this._oBlankCheckBox.Name = "_oBlankCheckBox";
            this._oBlankCheckBox.Size = new System.Drawing.Size(15, 14);
            this._oBlankCheckBox.TabIndex = 46;
            this._oBlankCheckBox.CheckedChanged += new System.EventHandler(this._oBlankCheckBox_CheckedChanged);
            //
            // _oOptionCheckBox
            //
            this._oOptionCheckBox.AutoSize = true;
            this._oOptionCheckBox.Location = new System.Drawing.Point(302, 175);
            this._oOptionCheckBox.Name = "_oOptionCheckBox";
            this._oOptionCheckBox.Size = new System.Drawing.Size(15, 14);
            this._oOptionCheckBox.TabIndex = 45;
            this._oOptionCheckBox.CheckedChanged += new System.EventHandler(this._oOptionCheckBox_CheckedChanged);
            //
            // label4
            //
            this.label4.AutoSize = true;
            this.label4.Location = new System.Drawing.Point(44, 144);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(33, 13);
            this.label4.TabIndex = 44;
            this.label4.Text = "Blank:";
            //
            // label3
            //
            this.label3.AutoSize = true;
            this.label3.Location = new System.Drawing.Point(44, 175);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(71, 13);
            this.label3.TabIndex = 43;
            this.label3.Text = "Enter String:";
            //
            // label1
            //
            this.label1.AutoSize = true;
            this.label1.Location = new System.Drawing.Point(44, 50);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(254, 13);
            this.label1.TabIndex = 42;
            this.label1.Text = "Please enter which option is default for this data type.";
            //
            // label6
            //
            this.label6.BackColor = System.Drawing.Color.Transparent;
            this.label6.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.label6.Location = new System.Drawing.Point(67, 87);
            this.label6.Name = "label6";
            this.label6.Size = new System.Drawing.Size(335, 2);
            this.label6.TabIndex = 41;
            //
            // label5
            //
            this.label5.AutoSize = true;
            this.label5.BackColor = System.Drawing.Color.Transparent;
            this.label5.ForeColor = System.Drawing.SystemColors.ActiveCaption;
            this.label5.Location = new System.Drawing.Point(9, 80);
            this.label5.Name = "label5";
            this.label5.Size = new System.Drawing.Size(42, 13);
            this.label5.TabIndex = 40;
            this.label5.Text = "Defaults";
            //
            // StringDataTypePropertyPage2
            //
            this.Controls.Add(this._oOptionTextBox);
            this.Controls.Add(this._oBlankCheckBox);
            this.Controls.Add(this._oOptionCheckBox);
            this.Controls.Add(this.label4);
            this.Controls.Add(this.label3);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.label6);
            this.Controls.Add(this.label5);
            this.Name = "StringDataTypePropertyPage2";
            this.Size = new System.Drawing.Size(411, 245);
            this.Leave += new System.EventHandler(this.StringDataTypePropertyPage2_Leave);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void _oBlankCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            _oOptionCheckBox.Checked = !_oBlankCheckBox.Checked;
            FireCanApplyChanged();
        }

        private void _oOptionCheckBox_CheckedChanged(object sender, EventArgs e)
        {
            _oBlankCheckBox.Checked = !_oOptionCheckBox.Checked;
            if (_oOptionCheckBox.Checked == true)
                _oOptionTextBox.Enabled = true;
            else
                _oOptionTextBox.Enabled = false;

            FireCanApplyChanged();
        }

        private void _oOptionTextBox_TextChanged(object sender, EventArgs e)
        {
            FireCanApplyChanged();
        }

        private void StringDataTypePropertyPage2_Leave(object sender, EventArgs e)
        {
            AllowNext(true);
            FireCanApplyChanged();
        }
    }
}
paulwhelanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

paulwhelanAuthor Commented:
BTW what are the CanApply and OnApply methods?
Thanks
Paul
levyukCommented:
The problem is that when the text is changed this method is fired - FireCanApplyChanged();

However in the above code that method doesn't exist. To enable the button you should put this line into this code

private void _oOptionTextBox_TextChanged(object sender, EventArgs e)
        {
            //FireCanApplyChanged();
buttonOk.Enabled = true;
        }

That should solve the button enabling problem.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.