none
Combobox - autocomplete ????

    Question

  • I have implemented this by changing the properties:

    Autocomplete - SuggestAppend
    AutocompleteSource - ListItems

    and it NEARLY works fine because ...

    if you have entered some keystrokes in the first place and "found" the right item in the combobox AND after try to pick another item by ALT+DownArrow then the combobox is some kind of "locked" to the keystrokes you entered in the first place.

    I think I have to "delete" the  keystrokes when I enter the combobox again - but where are those keystrokes stored ?

    Best regards KSO, Denmark
    Tuesday, June 16, 2009 8:59 AM

All replies

  • Hi PSAKSor,

     

    From  my experience, the steps to select a value on ComboBox ought to be like this:

    1.       Input some characters. If you enable auto complete mode, the drop down list will be shown and the items on it will be filtered.

    2.       Press key Up or Down to focus an item.

    3.       Press key Enter to select the item.

    The steps 2 and 3 can also be done by a mouse click on an item.

    Key Alt + Down/Up is used to show or hide the drop down list, not select one item.

     

    Could you give me more information about what you wanted to do or what problem you met? This will help me give you a better answer.

     

    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, June 18, 2009 7:18 AM
  • Hi Aland Li !

    You can "close the case" by saying that it's made so "by design" BUT ...

    Users DO things like this:

    TYPE IN - let's say 10 - and get some suggestens because of the setting of autocompleteMode - then they regret and press ALT-DownArrow to get more items to choose from - but now the entered keystrokes kind of "filters" the items they in fact CAN select with the UP/DOWN-arrows !

    In fact you can SEE the "un-selected entered keystrokes" when you tip up and down with the arrows.

    What I need is a method (by code) to "delete" those entered keystrokes - the keystrokes are NOT stored in the Text- or Tag-property - I tried that !

    Try make a sample and you will see the "problem" right away !

    You write:

    Key Alt + Down/Up is used to show or hide the drop down list, not select one item.


    Yes, that's right - but when the list IS dropped down you can use UP/DOWN arrows to choose and THEN press ENTER to select !



    Best regards KSO, Denmark
    • Edited by PSAKSor Thursday, June 18, 2009 8:05 AM
    Thursday, June 18, 2009 7:55 AM
  • Hi PSAKSor,

    I did reproduce you problem, but I think the behavior is reasonable. You set the auto complete mode to suggest append, so when you open the drop down list, it will select appropriate characters and append them to the characters you have typed. Although the drop down list is locked, but the selected part of the text, which is appended automatically, is still changed when you press the Up or Down key.

     

    If you wanted to be able to select any item when the drop down list is opened, you can just change the auto complete mode to suggest. In this case, the drop down list will not be locked and you can select any item.

     

    Let me know if this helps,

    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, June 18, 2009 10:18 AM
  • I'm sorry but you'r wrong !

    You still ONLY can choose - with arrows - among items containing the keystrokes !

    Try leave the combobox to some other textboxes on the form - when you come back to the combobox - it STILL remembers the keystrokes  !!!!!!!!

    This behavior is NOT reasonable I think !

    Best regards KSO, Denmark
    Thursday, June 18, 2009 10:24 AM
  • Hi PSAKSor,

     

    I’m sorry for not getting the key point about what you said, but I think I understand what you mean now. When the drop down list is shown, the behavior is a little strange. I think that is because the auto complete hint box get the focus. You can custom your own ComboBox and disable auto complete when the drop down list is shown and enable auto complete again when the drop down list is closed. This is my code snippet:

     

        public class MyComboBox : ComboBox

        {

            //indicate whether the drop down list is shown.

            private bool _isDropDownListShown = false;

     

            //Used to save the old states.

            private AutoCompleteMode _mode = AutoCompleteMode.None;

            private AutoCompleteSource _source = AutoCompleteSource.None;

     

     

            protected override void OnDropDown(EventArgs e)

            {

                _isDropDownListShown = true;

     

                //Save the old state.

                _mode = this.AutoCompleteMode;

                _source = this.AutoCompleteSource;

     

                //Disable auto complete mode to make the drop down list work correctly.

                this.AutoCompleteMode = AutoCompleteMode.None;

               

                base.OnDropDown(e);          

            }

     

            protected override void OnDropDownClosed(EventArgs e)

            {            

                base.OnDropDownClosed(e);

     

                //Recover the state.

                this.AutoCompleteMode = _mode;

                this.AutoCompleteSource = _source;

     

                _isDropDownListShown = false;

            }

     

            protected override void OnKeyDown(KeyEventArgs e)

            {          

                base.OnKeyDown(e);

     

                //When the drop down list is shown and user pressed Enter key, close the drop down list.

                if (_isDropDownListShown && e.KeyData == Keys.Enter)

                    this.OnDropDownClosed(new EventArgs());

            }

    }

     

    Let  me know if this helps.

    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Thursday, June 18, 2009 12:44 PM
  • A bette solution is to correct the error in ComboBox control ;-))

    Did you start that procedure ?

    BUT ... I'll try to create my own ComboBox - thanks for the answer.

    Best regards KSO, Denmark
    Monday, June 22, 2009 6:43 AM
  • Hi PSAKSor,

    I have explained the cause of the behavior of the control. I don’t think it’s an error. I agree with you that it’s not good to use or the behavior is a little strange. So I follow your advice and expand the control to let it better to use. Of course, if you wanted to make the control behavior completely satisfy your needs, creating your own ComboBox is a good idea.

    If you think it is a bug, you can send your feedback via this link:
    https://connect.microsoft.com/ .

    Aland Li
    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Monday, June 22, 2009 7:10 AM
  • Aland Li:

    I now have made a control, KSO_ComboBox, and a little testApp.

    It works if I use THE MOUSE and THE KEYBORAD to select items in the combobox, but if enter some keystrokes - two things happens:

    1) a dropdown list is floating on top of every thing else
    2)sometimes I get this error:

    A callback was made on a garbage collected delegate of type 'System.Windows.Forms!System.Windows.Forms.NativeMethods+WndProc::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.

    Here is the code for my KSO_ComboBox:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Data;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace KSO_CTRL_LIB
    {
        public partial class KSO_ComboBox : ComboBox
        {
            //indicate whether the drop down list is shown.
            private bool _isDropDownListShown = false;
            //Used to save the old states.
            private AutoCompleteMode _mode = AutoCompleteMode.None;
            private AutoCompleteSource _source = AutoCompleteSource.None;
    
            public KSO_ComboBox()
            {
                InitializeComponent();
            }
    
            protected override void OnDropDown(EventArgs e)
            {
                _isDropDownListShown = true;
                //Save the old state.
                _mode = this.AutoCompleteMode;
                _source = this.AutoCompleteSource;
                //Disable auto complete mode to make the drop down list work correctly.
                this.AutoCompleteMode = AutoCompleteMode.None;
                base.OnDropDown(e);
            }
    
            protected override void OnDropDownClosed(EventArgs e)
            {
                base.OnDropDownClosed(e);
                //Recover the state.
                this.AutoCompleteMode = _mode;
                this.AutoCompleteSource = _source;
                _isDropDownListShown = false;
            }
    
            protected override void OnKeyDown(KeyEventArgs e)
            {
                base.OnKeyDown(e);
                //When the drop down list is shown and user pressed Enter key, close the drop down list.
                if (_isDropDownListShown && e.KeyData == Keys.Enter)
                    this.OnDropDownClosed(new EventArgs());
            }
        }
    }
    

    Best regards KSO, Denmark
    Monday, June 22, 2009 12:26 PM
  • Hi PSAKSor,

    I tested the codes in my project, it works fine and I did not meet the error. Could you please provide me with your test code or test project? It can help to figure out the problem. Thanks.

    You can email to me: v-shunli@microsoft.com .

    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Tuesday, June 23, 2009 1:04 PM
  •  

    Hi PSAKSor,

    I received your email and tested your project. I did not meet the error: a dropdown list is floating on top of everything else. The program would throw an exception sometimes, I modified the code a little and did not meet it again while testing. Could you post the steps to reproduce the error, so I can follow your steps to debug the program. This is the modified code snippet:

    public partial class KSO_ComboBox : ComboBox

    {

        //indicate whether the drop down list is shown.

        private bool _isDropDownListShown = false;

        //Used to save the old states.

        private AutoCompleteMode _mode = AutoCompleteMode.None;

        private AutoCompleteSource _source = AutoCompleteSource.None;

     

        public KSO_ComboBox()

        {

            InitializeComponent();

        }

     

        protected override void OnDropDown(EventArgs e)

        {

            _isDropDownListShown = true;

            //Save the old state.

            _mode = this.AutoCompleteMode;

            _source = this.AutoCompleteSource;

            //Disable auto complete mode to make the drop down list work correctly.

            this.AutoCompleteMode = AutoCompleteMode.None;

            base.OnDropDown(e);

        }

     

        protected override void OnDropDownClosed(EventArgs e)

        {

            base.OnDropDownClosed(e);

            //Recover the state.

            this.AutoCompleteMode = _mode;

            this.AutoCompleteSource = _source;

            _isDropDownListShown = false;

        }

     

        protected override void OnKeyDown(KeyEventArgs e)

        {           

            //When the drop down list is shown and user pressed Enter key, close the drop down list.

            if (_isDropDownListShown && e.KeyData == Keys.Enter)

            {

                this.OnDropDownClosed(new EventArgs());

                e.Handled = true;

            }

            else

                base.OnKeyDown(e);

        }

    }

    Regards,
    Aland Li


    Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread.
    Wednesday, June 24, 2009 2:21 AM
  • Hi Aland Li !

    I pasted your changes and still I can get this floating window - this way (precisely):

    1) Start the test Form1 program
    2) press 'mn' - and the window comes up and I think that's OK
    3) press ALT+DownArrow - you allready can se the window in the back - and choose another and press ENTER

    the little window from 2) is still there - try move the form - it's floating

    QED - right ;-)) ?



    Best regards KSO, Denmark
    Wednesday, June 24, 2009 6:23 AM