Regardless of whether the Drop-down list is expanded, a carriage return must trigger a commit event, and ESC must trigger the cancellation event, resulting in unintended results.
MSDN contains:
Combobox.isinputkey method
protected override bool isInputKey (
Keys KeyData
)
The isInputKey method returns True if the KeyData parameter contains a return or Escape value and the Droppeddown property is true.
Logically, when a drop-down list expands, a carriage return does not trigger a commit event, and ESC does not trigger a cancellation event, but that is not the case.
Test code:
public class Comboboxex:combobox {
protected override bool isInputKey (Keys keyData)
{
if (droppeddown)
switch (keyData) {case
Keys.Return:return true;
Case Keys.Escape:return true;
}
Return base. isInputKey (KeyData);
}
You can see through the debugger that when the Drop-down list is not open, Droppeddown is false, isInputKey () executes it again, and behaves as expected. When the Drop-down list is open, the isInputKey () executes strangely two times, the first time Droppeddown is true, and the second droppeddown is false, causing isinputkey () to be fictitious, resulting in unintended results.
Solution:
public class Comboboxex:combobox {
protected bool Droppeddownbak = FALSE;
protected override bool isInputKey (Keys keyData)
{
if (Droppeddown | | Droppeddownbak) {
if (Droppeddownbak) Droppeddownbak = false;
if (droppeddown) Droppeddownbak = true;
Switch (keyData) {case
Keys.Return:return true;
Case Keys.Escape:return true;
}
}
Return base. isInputKey (KeyData);
}