如何通过编程将列表框中的行数/索引数从动态数量限制为常量(如5行)?例如,用户将数据从文本框输入到列表框直到第五行。如果他们再次尝试,程序将拒绝用户输入的数据,这将阻止列表框增加动态行大小。
我尝试使用选定的索引和选定的项目属性,例如:
if (ListBox1.SelectedItems.Count != 0)
{
while (ListBox1.SelectedIndex == 5)
{
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex);
}
}但是这些属性似乎需要选择一个列表框索引。
发布于 2019-03-29 15:36:34
if(ListBox1.Items.Count < 5){
ListBox1.Items.Add("asd");
}在插入时,您可以检查ListBox1中的项数是否小于5,并仅在其为真时才添加项,而不是删除。
https://stackoverflow.com/questions/55412431
复制相似问题