本文介绍了添加新项目之前,请检查列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想检查的项目尚不在列表框中存在之前,我添加新的项目。
I am trying to check that an item doesn't already exist in a list box before I add the new item.
if (TeamNameTextBox.Text != "")
{
if (TeamNameListBox.Items.FindByValue(TeamNameListBox.Text) == null)
{
TeamNameListBox.Items.Add(TeamNameTextBox.Text);
TeamNameTextBox.Text = "";
int teamCountUpdate = TeamNameListBox.Items.Count;
if (teamCountUpdate == 1)
{
TeamCount.Text = teamCountUpdate.ToString() + " Team";
}
else
{
TeamCount.Text = teamCountUpdate.ToString() + " Teams";
}
}
else
{
AddTeamSeasonError.Text = "This team has already been added";
}
}
else
{
AddTeamSeasonError.Text = "Please select a team";
}
我已经得到它来检查,如果文本框为空,但我需要检查用户尝试添加的项目是不是已经在列表框中。
I have got it to check if the text box is blank, but I need to check that the item a user is trying to add is not already in the the list box.
我已经试过行:
if (TeamNameListBox.Items.FindByValue(TeamNameListBox.Text) == null)
但是,这并不工作,我如何能做到检查有什么建议?
But that doesn't work, any suggestions on how I can do the check?
推荐答案
觉得你至少应该尝试使用 TeamNameTextBox
而不是 TeamNameListBox
作为参数
think you should at least try to use TeamNameTextBox
instead of TeamNameListBox
as argument
if (TeamNameListBox.Items.FindByValue(TeamNameTextBox.Text) == null)
这篇关于添加新项目之前,请检查列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!