Search code examples
c#winformswindow

combobox event & clear method


   private void ComboBox1_TextChanged(object sender, EventArgs e)
    {
        ComboBox1.Items.Clear();
        XmlNodeList node_lst = doc["paths"].ChildNodes;
        foreach (XmlNode item in node_lst)
        {
            if (item.InnerText.Contains(ComboBox1.Text))
            {
                ComboBox1.Items.Add(item.InnerText);
            }
        }            
    }

I am new in this website, i have question in this event when I clear items from combobox, I get these items from an xml file; my problem is when I enter letters in combobox text, the text is entered in inversed way, I expected that the problem in clear method but i have not idea how to do this. Thanks.


Solution

  • When you delete all items from the ComboBox the cursor will be set to the first position., So after each character that you type the cursor will be shifted to the left and you get the feeling of typing from right to left.

    The solution would be to set the SelectionStart after the for-loop by hand to the end of the Text:

    comboBox1.SelectionStart = comboBox1.Text.Length;