组合框事件和清除方法

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);
            }
        }            
    }

我是这个网站的新手,当我从组合框中清除项目时,我对这个事件有疑问,我从 xml 文件中获取这些项目;我的问题是当我在组合框文本中输入字母时,文本以相反的方式输入,我预计问题会以清晰的方法出现,但我不知道如何做到这一点。 谢谢

当您删除 ComboBox 中的所有项目时,光标将设置为第一个位置。因此,在您键入每个字符后,光标将向左移动,您会获得键入的感觉从右到左。

解决方案是将 for 循环后的 SelectionStart 手动设置到 Text 的末尾:

comboBox1.SelectionStart = comboBox1.Text.Length;

我猜你想要这样的东西:

var nodeList = node_lst.Cast<XmlNode>()
                               .Select(x => library.GetMemberName(int.Parse(x.InnerText)))
                               .ToList();
nodeList.Reverse();

关于 Reverse() 的更多信息:https://msdn.microsoft.com/en-us/library/b0axc2h2(v=vs.110).aspx