在组合框中查找字符串

时间:2021-01-27 10:12:54

标签: c# combobox special-characters

我有一个包含特殊字符的字符串值,如 í、é、ë、ï 等。例如“San Luis Potosí”。此值已从表单上的组合框应用于我的应用程序中的字段。稍后我想在组合框中再次找到该值,以便组合框已经显示该值。对于“正常”值,它按预期工作,并且组合框显示正确的值,但对于“San Luis Potosí”、“'s-Hertogenbosch”等值则不是。对于这些特殊字符,我有什么特别的事情要做吗?

编辑:

//Example:
txtLocation = "San Luis Potosí, Mexico";

string[] location = txtLocation.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries);
                string city = location[0]; // city = "San Luis Potosí" (this works)
                string country = location[1]; // country = "Mexico" (this works)

                comboBoxCountry.SelectedIndex = comboBoxCountry.FindStringExact(country);
                comboBoxCity.SelectedIndex = comboBoxCity.FindStringExact(city);

组合框由数据库中的数据集归档。我正在使用 winforms,框架 .Net 4.6.1。

我只是注意到它没有任何价值。似乎与任何特殊字符无关。

我在调试时得到这些值。 comboBoxCountry.SelectedIndex = -1 comboBoxCity.SelectedIndex = -1

1 个答案:

答案 0 :(得分:0)

我想通了,加载数据库的方法被调用了两次并覆盖了找到的值。

相关问题