there is a listview which stores names from my a textbox and when i select a single name from a row in my listview i want that name to be shown back in my textbox. how can i make it ? there is a people LIst i have stored all the person details
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;
}
you need to set the View
of ListView to the List
.
Add follwoing statements in form_Load:
listView1.View = View.List;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.