Hi people, i need to delete selected row in ListView from xml file..

i have this code:

private void tsBtnDeleteRow_Click(object sender, EventArgs e)
        {
            if (listView1.SelectedItems.Count == 0) return;
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load("diogomonteiro.xml");
            //XmlNodeList newXMLNodes = xmlDoc.SelectNodes("/Pessoas/Pessoa[name=wd]");
            PessoaListViewItem item = (PessoaListViewItem)listView1.SelectedItems[0];
            string value = item.ToString();

            if (item != null)
            {
                MessageBox.Show("A pessoa a remover é: " + item.MinhaPessoa.nome);

                foreach (XmlNode xNode in xmlDoc.SelectNodes("Pessoas"))
                {
                    if (xNode.SelectSingleNode("Pessoa").InnerText == value)
                    {
                        xNode.ParentNode.RemoveChild(xNode);
                        xmlDoc.Save("diogomonteiro.xml");
                    }

                }
            }
            else
            {
                this.listView1.SelectedItems.Clear();
                MessageBox.Show("Nenhuma pessoa seleccionada");
            }
            listView1.SelectedItems[0].Remove();




        }

and this xml file:

<Pessoas>
  <Pessoa>
    <Nome>wd</Nome>
    <Idade>ef</Idade>
    <Profissao>ecf</Profissao>
    <Signo>wece</Signo>
    <Morada>ce</Morada>
    <Telemovel>ce</Telemovel>
    <Email>c</Email>
  </Pessoa>
  <Pessoa>
    <ID>8b67de50</ID>
    <Nome>Ddfwdf</Nome>
    <Idade>wefwe</Idade>
    <Profissao>wef</Profissao>
    <Signo>wef</Signo>
    <Morada>wef</Morada>
    <Telemovel>wefwef</Telemovel>
    <Email>wef</Email>
  </Pessoa>
  </Pessoas>

Who can help?
Thanks and Happy BirthDay for me :)

Are you trying to remove all the data from within the Pessoa Element? That's what the if statement that checks against value looks to be doing to me.

What do you want the XML to look like when you are done?

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.