且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将项目添加到Windows窗体应用程序的listBox中,

更新时间:2023-12-06 13:12:22

好吧,看来您正在首先添加名称TextBox中的值,然后又添加了出生日期TextBox中的值.由于此处的出生日期为空,因此在列表框上将获得一个空字符串(因此为一个空行).

Well, it looks like you're first adding the value from the name TextBox and then the value from the Birth date TextBox. Since birth date is empty here, you'll get an empty string (thus an empty row) on the ListBox.

如果您不想添加空值,则应在调用Add方法之前检查它们:

If you don't want empty values added, you should check for them before the call to the Add method:

if (equal2 == false && !string.IsNullOrEmpty(textBox2.Text)
{
    listBox1.Items.Add(textBox2.Text);
}

但是,您正在做的事情似乎不是很简单.我建议您重新考虑检查值和处理值的方式.

However, what you're doing doesn't seem very straight forward. I'd recommend yo rethink the way you check for values and process them.