[英]show listview item in a textbox
有一個列表視圖,用於存儲我的文本框中的名稱,當我從列表視圖中的一行中選擇一個名稱時,我希望該名稱顯示在我的文本框中。 我該怎么做? 我已經存儲了所有人的詳細信息
List<person> people = new List<person>();
private void Form1_Load(object sender, EventArgs e)
{
String path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
if(!Directory.Exists(path+"\\AddressBook Data\\"))
Directory.CreateDirectory(path+"\\AddressBook Data\\");
if(!File.Exists(path+"\\AddressBook Data\\PeopleData.xml"))
File.Create(path +"\\AddressBook Data\\PeopleData.xml");
}
private void button2_Click(object sender, EventArgs e)
{
person p = new person();
p.name = textBox1.Text;
p.email = textBox2.Text;
p.streetAddress = textBox3.Text;
p.birthday = dateTimePicker1.Value;
p.addtionalNote = textBox4.Text;
people.Add(p);
listView1.Items.Add(p.name);
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
textBox4.Text = "";
dateTimePicker1.Value = DateTime.Now;
}
您需要將ListView的View
設置為List
。
在form_Load中添加以下語句:
listView1.View = View.List;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.