我的组合框中的一些项目长度超过20个字符,我编写了这个代码以使它们更小并添加“...”,但它不起作用。 例如,而不是“comboboxitemnumberthree”它看起来是这样的:“comboboxitemnu ...”,以适应组合框组合框项太长
i=0;
do
{
var item = comboBox1.Items[i].ToString();
if (item.Length >= 17) // not sure about this part
{
item = item.Substring(0, item.Length - 6) + "...";
}
i++;
} while (i < comboBox1.Items.Count); //finishes when theres not any other item left on the combobox
请让我知道什么是错的大小。提前致谢。
它不工作,但为什么我应该避免做什么? – 2014-09-21 22:13:47
这不能用于其他原因。你不能改变在foreach中使用的迭代器。项目在这里只读。 – Steve 2014-09-21 22:18:53
@Isaac:在这种情况下,你应该避免使用'do while',因为正常的'for(var i = 0 ...)'循环更简单。 – 2014-09-21 22:21:28