本文介绍了Windows程序设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以告诉我如果两者都在同一页面上时如何在文本框中向列表框中添加文本吗?这是我自己尝试的代码:
Could someone please show me how to add text in textbox to listbox if both are on the same page? This is the code I tried myself:
string temp ;
temp = txtData.Text;
lstDataList.Text += temp;
推荐答案
lstDataList.Items.Add(txtData.Text);
但是,您应该对重复的条目非常小心,因为此代码不会检查重复的条目.
因此,
However, you should really be careful about duplicate entries, as this code does not check for duplicate entries.
Hence,
if(lstDataList.Items.Contains(txtData.Text)==false)
{
lstDataList.Items.Add(txtData.Text);
}
lstDataList.Items.Add( txtData.Text );
祝你好运!
Good luck!
这篇关于Windows程序设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!