Roman

Roman

  • NA
  • 5
  • 1.2k

ListView SortOrder Ascending changing textbox values

Sep 28 2013 1:48 PM
Hi everybody

I'm writing a program in which I can add items to a ListView control given by VS2012. I want to add surname and forename. Adding items works perfectly. But if I want to sort it ascending it changes the textbox values by restarting program. For example:


I got 2 Person: Joe Miller and Richard Brown. If I add them, it sorts fine (First is "Brown Richard" and then comes "Miller Joe"). If I now restart the program the ListView items are: First: "Joe Miller" - Second: "Richard Brown". So it changes surname and forename.


Can someone give me a hint how I possibly can fix this? I tried to use the "Sorting" property in VS2012 and now I'm using this code:


private void Form1_Load(object sender, EventArgs e)
        {
            listViewKunden.Sorting = SortOrder.Ascending;
        }



Thanks in advance

EDIT: I asked the same question here, unfortunately get no answer: Link to question
There you can see more code (how I add item to listView)

EDIT 2: Here you can see how I add items to listView:

private void btnAddItem_Click(object sender, EventArgs e)
        {
            if(!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            if (!File.Exists(path + "\\save.xml"))
            {
                XmlTextWriter xwriter = new XmlTextWriter(path + "\\save.xml", Encoding.UTF8);
                xwriter.WriteStartElement("Kundenverwaltung");
                xwriter.WriteEndElement();
                xwriter.Close();
            }

            Kunde k = new Kunde();
            k.KundenNr = txtKundenNr.Text;
            k.Nachname = txtKundeNachname.Text;
            k.Vorname = txtKundeVorname.Text;
            k.Adresse = txtKundeAdresse.Text;
            k.Ort = txtKundeOrt.Text;
            k.Telefon = txtKundeTel.Text;
            k.Mail = txtKundeMail.Text;

            kunde.Add(k);
            listViewKunden.Items.Add(k.Nachname + " " + k.Vorname);

            txtKundenNr.Text = "";
            txtKundeNachname.Text = "";
            txtKundeVorname.Text = "";
            txtKundeAdresse.Text = "";
            txtKundeOrt.Text = "";
            txtKundeTel.Text = "";
            txtKundeMail.Text = "";
        }

Answers (2)