ComboBoxCellType events problem

Posted by: spif2001 on 8 September 2017, 2:27 pm EST

  • Posted 8 September 2017, 2:27 pm EST

    Hi

     I'm having a couple of problems with the ComboBoxCellType. I'm using the latest spread for winforms.

     Scenario: On an empty form I add a FpSpread and via the farpoint designer i set the celltype of cell 0,0 to be a ComboBoxCellType and add three values ("One", "Two", "Three"). I add the EditModeOff and EditModeOn events from the spread and the Activated and Deactivate events from the form.

     See the code at the end of this post.

     1) When I click the combobox and get the DropDown event, I also get a Deactivate event fired on the form? The form has it's Activated event fired again when selecting an item or pressing Enter or Esc - i.e. when the ComboBox loses focus. I have code in some of my non-test forms' Deactivate / Activated events, and I'm not interested in having it run just because a user uses a spread combobox. Is there a way to stop this behavior, or is it a bug?

     2) When I dropdown the combobox and uses Arrow keys, Enter and Esc to navigate it, I no longer receive PreviewKeyDown events. I need to know if the user presses Esc in order to leave the cell with the value it had before the dropdown. Fx. if before the dropdown the value is "One", and I press Return to dropdown, I get the PreviewKeyDown event with Return as value, but when the combobox is dropped down the PreviewKeyDown events stops firing. I then navigate to the value "Three" via the Arrow keys but regrets my decision and press Esc. But when the combobox collapses "Three" is the value in the Cell and it ought to be "One." This I would do by capturing the Esc key, but since I don't get any PreviewKeyDown events, I can't. What to do?

    [TestForm2]

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace Test_Spread
    {
        public partial class TestForm2 : Form
        {
            public TestForm2()
            {
                InitializeComponent();
            }
           
            private void TestForm2_Activated(object sender, EventArgs e)
            {
                Console.WriteLine("Form Activated");
            }

            private void TestForm2_Deactivate(object sender, EventArgs e)
            {
                Console.WriteLine("Form Deactivated");
            }

            private void spread_EditModeOn(object sender, EventArgs e)
            {
                Type type = spread.EditingControl.GetType();
                if (type == typeof(FarPoint.Win.FpCombo))
                {
                    FarPoint.Win.FpCombo comboeditor = (FarPoint.Win.FpCombo)spread.EditingControl;
                    comboeditor.Focus();
                    comboeditor.CloseUp += new EventHandler(comboeditor_CloseUp);
                    comboeditor.DropDown += new FarPoint.Win.DropDownEventHandler(comboeditor_DropDown);
                    comboeditor.PreviewKeyDown += new PreviewKeyDownEventHandler(comboeditor_PreviewKeyDown);
                }
            }

            void comboeditor_CloseUp(object sender, EventArgs e)
            {
                Console.WriteLine("Closeup");
            }

            void comboeditor_DropDown(object sender, FarPoint.Win.DropDownEventArgs e)
            {
                Console.WriteLine("DropDown");
            }

            void comboeditor_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
            {
                Console.WriteLine("PreviewKeyDown");
            }

            private void spread_EditModeOff(object sender, EventArgs e)
            {
                Type type = spread.EditingControl.GetType();
                if (type == typeof(FarPoint.Win.FpCombo))
                {
                    FarPoint.Win.FpCombo comboeditor = (FarPoint.Win.FpCombo)spread.EditingControl;
                    comboeditor.CloseUp -= new EventHandler(comboeditor_CloseUp);
                    comboeditor.DropDown -= new FarPoint.Win.DropDownEventHandler(comboeditor_DropDown);
                    comboeditor.PreviewKeyDown -= new PreviewKeyDownEventHandler(comboeditor_PreviewKeyDown);
                }
            }
        }
    }

     

    [TestForm2.Designer]

    namespace Test_Spread
    {
        partial class TestForm2
        {
            private System.ComponentModel.IContainer components = null;

            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }

            private void InitializeComponent()
            {
                FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType2 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
                this.spread = new FarPoint.Win.Spread.FpSpread();
                this.spread_Sheet1 = new FarPoint.Win.Spread.SheetView();
                ((System.ComponentModel.ISupportInitialize)(this.spread)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.spread_Sheet1)).BeginInit();
                this.SuspendLayout();
                //
                // spread
                //
                this.spread.AccessibleDescription = "";
                this.spread.Location = new System.Drawing.Point(10, 15);
                this.spread.Name = "spread";
                this.spread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {
                this.spread_Sheet1});
                this.spread.Size = new System.Drawing.Size(417, 190);
                this.spread.TabIndex = 0;
                this.spread.EditModeOn += new System.EventHandler(this.spread_EditModeOn);
                this.spread.EditModeOff += new System.EventHandler(this.spread_EditModeOff);
                //
                // spread_Sheet1
                //
                this.spread_Sheet1.Reset();
                this.spread_Sheet1.SheetName = "Sheet1";
                // Formulas and custom names must be loaded with R1C1 reference style
                this.spread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;
                spread_Sheet1.ColumnCount = 3;
                spread_Sheet1.RowCount = 5;
                comboBoxCellType2.ButtonAlign = FarPoint.Win.ButtonAlign.Right;
                comboBoxCellType2.Items = new string[] {
            "One",
            "Two",
            "Three"};
                this.spread_Sheet1.Cells.Get(0, 0).CellType = comboBoxCellType2;
                this.spread_Sheet1.RowHeader.Columns.Default.Resizable = false;
                this.spread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;
                //
                // TestForm2
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(446, 241);
                this.Controls.Add(this.spread);
                this.Name = "TestForm2";
                this.Text = "TestForm2";
                this.Activated += new System.EventHandler(this.TestForm2_Activated);
                this.Deactivate += new System.EventHandler(this.TestForm2_Deactivate);
                ((System.ComponentModel.ISupportInitialize)(this.spread)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.spread_Sheet1)).EndInit();
                this.ResumeLayout(false);

            }

            private FarPoint.Win.Spread.FpSpread spread;
            private FarPoint.Win.Spread.SheetView spread_Sheet1;
        }
    }

  • Replied 8 September 2017, 2:27 pm EST

    Ok - solved the PreviewKeyDown problem by setting the ListControl on the ComboBox (see code below).

     But it still leaves me with the problem of the form's deactivate and activated events being fired.

     



    Normal
    0


    21


    false
    false
    false

    DA
    X-NONE
    X-NONE













    MicrosoftInternetExplorer4



























































































































































    /* Style Definitions */
    table.MsoNormalTable
    {mso-style-name:"Tabel - Normal";
    mso-tstyle-rowband-size:0;
    mso-tstyle-colband-size:0;
    mso-style-noshow:yes;
    mso-style-priority:99;
    mso-style-qformat:yes;
    mso-style-parent:"";
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-para-margin:0cm;
    mso-para-margin-bottom:.0001pt;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:"Times New Roman";
    mso-fareast-theme-font:minor-fareast;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;}



    comboeditor.ListControl
    = new
    myListBox();



    class myListBox
    : ListBox



    {

      protected override
    bool ProcessCmdKey(ref
    Message msg, Keys
    keyData)



      {

        return base.ProcessCmdKey(ref msg, keyData);



      }



    }



     

  • Replied 8 September 2017, 2:27 pm EST

    We have been able to reproduce your issue, it is a bug and will be reported for a fix. Unfortunately we are currently preparing the next maintenance release scheduled for Oct12th and this fix will not make it into that release. It is more likely to be out in the January time frame
  • Replied 8 September 2017, 2:27 pm EST

    Ok - I look forward to an early 2011 update then. :)

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels