using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        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 + "\\Address Book"))
                Directory.CreateDirectory(path + "\\Address Book");
            if (!File.Exists(path + "\\Address Book \\settings.Xml"))
            {

                    XmlTextWriter xW = new XmlTextWriter(path + "\\Address Book \\settings.Xml", Encoding.UTF8);
                    xW.WriteStartElement("People");
                    xW.WriteEndElement();
                    xW.Close();

            }

            XmlDocument xDocument = new XmlDocument();
            xDocument.Load(path + "\\Address Book\\settings.Xml");
            foreach (XmlNode xNode in xDocument.SelectNodes("People/Person")) 
            {
                    Person p = new Person();
                    p.Name = xNode.SelectSingleNode("Name").InnerText;
                    p.Number = xNode.SelectSingleNode("Number").InnerText;
                    p.Email = xNode.SelectSingleNode("Email").InnerText;
                    p.Address = xNode.SelectSingleNode("Address").InnerText;
                    p.Birthday = DateTime.FromFileTime(Convert.ToInt64(xNode.SelectSingleNode("Birthday").InnerText));
                    people.Add(p);
                    listView1.Items.Add(p.Name);
            }
        }
        //add
        private void button1_Click(object sender, EventArgs e)
        {
            Person p = new Person();

            p.Name = textBox1.Text;
            p.Number = textBox2.Text;
            p.Email = textBox3.Text;
            p.Address = textBox4.Text;
            p.Birthday = dateTimePicker1.Value;
            people.Add(p);
            listView1.Items.Add(p.Name);
            textBox1.Text = "";
            textBox2.Text = "";
            textBox3.Text = "";
            textBox4.Text = "";
            dateTimePicker1.Value = DateTime.Now;
        }
        //viewlist
        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

            try
            {
                textBox1.Text = people[listView1.SelectedItems[0].Index].Name;
                textBox2.Text = people[listView1.SelectedItems[0].Index].Number;
                textBox3.Text = people[listView1.SelectedItems[0].Index].Email;
                textBox4.Text = people[listView1.SelectedItems[0].Index].Address;
                dateTimePicker1.Value = people[listView1.SelectedItems[0].Index].Birthday;
            }
            catch { };

        }
        //remove
        private void button3_Click(object sender, EventArgs e)
        {
            Remove();
        }
        // remove
        void Remove()
        {
            try
            {
                listView1.Items.Remove(listView1.SelectedItems[0]);
                people.RemoveAt(listView1.SelectedItems[0].Index);
            }
            catch { };
        }
        //remove
        private void removeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Remove();
        }
        //save
        private void button2_Click(object sender, EventArgs e)
        {

                people[listView1.SelectedItems[0].Index].Name = textBox1.Text;
                people[listView1.SelectedItems[0].Index].Number = textBox2.Text;
                people[listView1.SelectedItems[0].Index].Email = textBox3.Text;
                people[listView1.SelectedItems[0].Index].Address = textBox4.Text;
                people[listView1.SelectedItems[0].Index].Birthday = dateTimePicker1.Value;
                listView1.SelectedItems[0].Text = textBox1.Text;

        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {

            XmlDocument xDocument = new XmlDocument();
                string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                xDocument.Load(path + "\\Address Book \\settings.Xml");
                XmlNode xNode = xDocument.SelectSingleNode("People");
                xNode.RemoveAll();

                foreach (Person p in people)
                {
                    XmlNode xTop = xDocument.CreateElement("Person");
                    XmlNode xName = xDocument.CreateElement("Name");
                    XmlNode xNumber = xDocument.CreateElement("Number");
                    XmlNode xEmail = xDocument.CreateElement("Email");
                    XmlNode xAddress = xDocument.CreateElement("Address");
                    XmlNode xBrithday = xDocument.CreateElement("Brithday");
                    xName.InnerText = p.Name;
                    xNumber.InnerText = p.Number;
                    xEmail.InnerText = p.Email;
                    xAddress.InnerText = p.Address;
                    xBrithday.InnerText = p.Birthday.ToFileTime().ToString();
                    xTop.AppendChild(xName);
                    xTop.AppendChild(xNumber);
                    xTop.AppendChild(xEmail);
                    xTop.AppendChild(xAddress);
                    xTop.AppendChild(xBrithday);
                    xDocument.DocumentElement.AppendChild(xTop);
                }
                xDocument.Save(path + "\\Address Book \\settings.Xml");

        }
        //search in textbox5
        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void toolTip1_Popup(object sender, PopupEventArgs e)
        {

        }


    }
    class Person
    {
        public string Name
        {
            get;
            set;
        }

        public string Number
        {
            get;
            set;
        }

        public string Email
        {
            get;
            set;
        }

        public string Address
        {
            get;
            set;
        }

        public DateTime Birthday
        {
            get;
            set;
        }
    }
}

need help with searching and the toltips and get the names in the listview box when it lords up arther you type something and than close the program

What are you in search for?
Could you please rephrase your question, it's hardly understandable.

i need to search a list of names thet user puts in?
i need the listview box that contains the names to keep them in the box even after you close it?

You could store the ListBoxItems in the Properties.Settings. Will perhaps explain more tomorrow.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.