Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ComboBox Cell text typing causes "Error creating window handle" #7

Closed
cuppm opened this issue Jan 11, 2023 · 1 comment
Closed

ComboBox Cell text typing causes "Error creating window handle" #7

cuppm opened this issue Jan 11, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@cuppm
Copy link

cuppm commented Jan 11, 2023

Something from the Siemens update to the ComboBox editor is causing a "Error creating window handle" exception to be thrown when a value is changed in a cell that already has a value.

Steps to Reproduce

  1. Create new .NET framework project w/ reference to SourceGrid and paste in Form Code from below and run app
  2. Pick a body grid cell and enter a text value (e.g. "1")
  3. Tab out of the cell
  4. Go back into the cell that had text entered and press a key for a new value to trigger the exception to be thrown

Notes/Comments

  1. In my actual project I'm using the grid and combobox cell control to allow the user to enter a numeric value or one of the predefined flags from the enum
  2. I'm using a SourceGrid.Cells.Controller.ControllerBase derived implementation that persists the string value to the underlying model object (and checks that non-numeric strings are one of the enum values).
  3. This error did not show up in the last version of the code found on the CodePlex repository (version 4.40) and appears to be related to the changes made in this repository that were committed by @sandhraprakash (sorry for the tag - hoping you'd know what might be the issue) where the SourceGrid.Cells.Editors.ComboBox had its reference to a DevAge.Windows.Forms.DevAgeComboBox replaced with the new class DevAge.Windows.Forms.UIComboBox

Form Code

using System;
using System.Windows.Forms;

namespace TestingCombobox {
    internal static class Program {
        public enum EnumOptions {
            A,
            B,
            C,
        }

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            EnumOptions[] oOptions = (EnumOptions[]) Enum.GetValues(typeof(EnumOptions));

            Form oForm = new Form();
            SourceGrid.Grid oGrid = new SourceGrid.Grid() {
                Dock = DockStyle.Fill,
            };
            oGrid.Redim(4, 4);
            for (int i = 0; i < 3; i++) {
                oGrid[0, i + 1] = new SourceGrid.Cells.ColumnHeader((i + 1).ToString());
                oGrid[i + 1, 0] = new SourceGrid.Cells.RowHeader((i + 1).ToString());
            }
            for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 3; j++) {
                    SourceGrid.Cells.Editors.ComboBox oEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(string), oOptions, false);
                    oGrid[i + 1, j + 1] = new SourceGrid.Cells.Cell(null, oEditor);
                }
            }
            oForm.Controls.Add(oGrid);

            Application.Run(oForm);
        }
    }
}
@cuppm
Copy link
Author

cuppm commented Jan 11, 2023

It appears to be from the change in SourceGrid\Cells\Editors\EditorControlBase.cs line 137 in InternalStartEdit() where the control was moved "here for improved performance". But it doesn't check whether a control was already created, so it just keeps creating new ones every time it starts an edit.

Old code:

//[email protected]: moved from constructor to here to improve performance
mControl = CreateControl();

Fixed code:

//[email protected]: moved from constructor to here to improve performance
if (mControl == null) 
	mControl = CreateControl();

I'm still trying to figure out Github and will try to submit a patch.

Also another bug fix is needed in SourceGrid\Cells\Editors\EditorControlBase.cs line 151:
Old code:
c# Control.Text = key.ToString();
Fixed code:
c# Control.ComboBox.Text = key.ToString();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants