ComboBoxCellType events problem

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

  • Posted 8 September 2017, 2:27 pm EST

    <p>Hi</p><p> I'm having a couple of problems with the ComboBoxCellType. <font size="2">I'm using the latest spread for winforms.</font></p><p> 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.</p><p> See the code at the end of this post.<br></p><p> 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?</p><p> 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?<br></p><p><b>[TestForm2] </b><br></p><p><font face="courier new,courier" size="2">using System;<br>using System.Collections.Generic;<br>using System.ComponentModel;<br>using System.Data;<br>using System.Drawing;<br>using System.Linq;<br>using System.Text;<br>using System.Windows.Forms;<br><br>namespace Test_Spread<br>{<br>    public partial class TestForm2 : Form<br>    {<br>        public TestForm2()<br>        {<br>            InitializeComponent();<br>        }<br>        <br>        private void TestForm2_Activated(object sender, EventArgs e)<br>        {<br>            Console.WriteLine("Form Activated");<br>        }<br><br>        private void TestForm2_Deactivate(object sender, EventArgs e)<br>        {<br>            Console.WriteLine("Form Deactivated");<br>        }<br><br>        private void spread_EditModeOn(object sender, EventArgs e)<br>        {<br>            Type type = spread.EditingControl.GetType();<br>            if (type == typeof(FarPoint.Win.FpCombo))<br>            {<br>                FarPoint.Win.FpCombo comboeditor = (FarPoint.Win.FpCombo)spread.EditingControl;<br>                comboeditor.Focus();<br>                comboeditor.CloseUp += new EventHandler(comboeditor_CloseUp);<br>                comboeditor.DropDown += new FarPoint.Win.DropDownEventHandler(comboeditor_DropDown);<br>                comboeditor.PreviewKeyDown += new PreviewKeyDownEventHandler(comboeditor_PreviewKeyDown);<br>            }<br>        }<br><br>        void comboeditor_CloseUp(object sender, EventArgs e)<br>        {<br>            Console.WriteLine("Closeup");<br>        }<br><br>        void comboeditor_DropDown(object sender, FarPoint.Win.DropDownEventArgs e)<br>        {<br>            Console.WriteLine("DropDown");<br>        }<br><br>        void comboeditor_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)<br>        {<br>            Console.WriteLine("PreviewKeyDown");<br>        }<br><br>        private void spread_EditModeOff(object sender, EventArgs e)<br>        {<br>            Type type = spread.EditingControl.GetType();<br>            if (type == typeof(FarPoint.Win.FpCombo))<br>            {<br>                FarPoint.Win.FpCombo comboeditor = (FarPoint.Win.FpCombo)spread.EditingControl;<br>                comboeditor.CloseUp -= new EventHandler(comboeditor_CloseUp);<br>                comboeditor.DropDown -= new FarPoint.Win.DropDownEventHandler(comboeditor_DropDown);<br>                comboeditor.PreviewKeyDown -= new PreviewKeyDownEventHandler(comboeditor_PreviewKeyDown);<br>            }<br>        }<br>    }<br>}</font><br> </p><p><b>[TestForm2.Designer] </b></p><p><font face="courier new,courier">namespace Test_Spread<br>{<br>    partial class TestForm2<br>    {<br>        private System.ComponentModel.IContainer components = null;<br><br>        protected override void Dispose(bool disposing)<br>        {<br>            if (disposing && (components != null))<br>            {<br>                components.Dispose();<br>            }<br>            base.Dispose(disposing);<br>        }<br><br>        private void InitializeComponent()<br>        {<br>            FarPoint.Win.Spread.CellType.ComboBoxCellType comboBoxCellType2 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();<br>            this.spread = new FarPoint.Win.Spread.FpSpread();<br>            this.spread_Sheet1 = new FarPoint.Win.Spread.SheetView();<br>            ((System.ComponentModel.ISupportInitialize)(this.spread)).BeginInit();<br>            ((System.ComponentModel.ISupportInitialize)(this.spread_Sheet1)).BeginInit();<br>            this.SuspendLayout();<br>            // <br>            // spread<br>            // <br>            this.spread.AccessibleDescription = "";<br>            this.spread.Location = new System.Drawing.Point(10, 15);<br>            this.spread.Name = "spread";<br>            this.spread.Sheets.AddRange(new FarPoint.Win.Spread.SheetView[] {<br>            this.spread_Sheet1});<br>            this.spread.Size = new System.Drawing.Size(417, 190);<br>            this.spread.TabIndex = 0;<br>            this.spread.EditModeOn += new System.EventHandler(this.spread_EditModeOn);<br>            this.spread.EditModeOff += new System.EventHandler(this.spread_EditModeOff);<br>            // <br>            // spread_Sheet1<br>            // <br>            this.spread_Sheet1.Reset();<br>            this.spread_Sheet1.SheetName = "Sheet1";<br>            // Formulas and custom names must be loaded with R1C1 reference style<br>            this.spread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.R1C1;<br>            spread_Sheet1.ColumnCount = 3;<br>            spread_Sheet1.RowCount = 5;<br>            comboBoxCellType2.ButtonAlign = FarPoint.Win.ButtonAlign.Right;<br>            comboBoxCellType2.Items = new string[] {<br>        "One",<br>        "Two",<br>        "Three"};<br>            this.spread_Sheet1.Cells.Get(0, 0).CellType = comboBoxCellType2;<br>            this.spread_Sheet1.RowHeader.Columns.Default.Resizable = false;<br>            this.spread_Sheet1.ReferenceStyle = FarPoint.Win.Spread.Model.ReferenceStyle.A1;<br>            // <br>            // TestForm2<br>            // <br>            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);<br>            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;<br>            this.ClientSize = new System.Drawing.Size(446, 241);<br>            this.Controls.Add(this.spread);<br>            this.Name = "TestForm2";<br>            this.Text = "TestForm2";<br>            this.Activated += new System.EventHandler(this.TestForm2_Activated);<br>            this.Deactivate += new System.EventHandler(this.TestForm2_Deactivate);<br>            ((System.ComponentModel.ISupportInitialize)(this.spread)).EndInit();<br>            ((System.ComponentModel.ISupportInitialize)(this.spread_Sheet1)).EndInit();<br>            this.ResumeLayout(false);<br><br>        }<br><br>        private FarPoint.Win.Spread.FpSpread spread;<br>        private FarPoint.Win.Spread.SheetView spread_Sheet1;<br>    }<br>}</font> <br></p>
  • Replied 8 September 2017, 2:27 pm EST

    <p>Ok - solved the PreviewKeyDown problem by setting the ListControl on the ComboBox (see code below).</p><p> But it still leaves me with the problem of the form's deactivate and activated events being fired.</p><p> </p><p>






    /* Style Definitions */
    {mso-style-name:"Tabel - Normal";
    mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
    mso-fareast-font-family:"Times New Roman";
    mso-bidi-font-family:"Times New Roman";

    </p><p><span style="font-size:10pt;font-family:Consolas;color:blue;">comboeditor.ListControl
    = new </span><span style="font-size:10pt;font-family:Consolas;">myListBox</span><span style="font-size:10pt;font-family:Consolas;color:blue;">();<br></span></p>

    <p><span style="font-size:10pt;font-family:Consolas;color:blue;">class</span><span style="font-size:10pt;font-family:Consolas;"> <span>myListBox</span>
    : <span>ListBox</span></span></p>

    <p><span style="font-size:10pt;font-family:Consolas;color:blue;">{</span></p><p><span style="font-size:10pt;font-family:Consolas;color:blue;">  protected</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">override</span>
    <span style="color:blue;">bool</span> ProcessCmdKey(<span style="color:blue;">ref</span>
    <span>Message</span> msg, <span>Keys</span>

    <p><span style="font-size:10pt;font-family:Consolas;">  {</span></p><p><span style="font-size:10pt;font-family:Consolas;color:blue;">    return</span><span style="font-size:10pt;font-family:Consolas;"> <span style="color:blue;">base</span>.ProcessCmdKey(<span style="color:blue;">ref</span> msg, keyData);</span></p>

    <p><span style="font-size:10pt;font-family:Consolas;">  }</span></p>

    <p><span style="font-size:10pt;font-family:Consolas;">}</span></p>

    <p> </p>
  • 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

    <p>Ok - I look forward to an early 2011 update then. :)</p>
Need extra support?

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

Learn More

Forum Channels