I'm making a simple Contact Manager as a practice project based on a XML file everything is working just fine except for two problems
Every time I click on the white blank space on ListBox, I get this exception:
Object reference not set to an instance of an object.
It doesn't happen if an item is selected on the ListBox though.
Code:
private void lstbox1_SelectedIndexChanged(object sender, EventArgs e)
{
btnDelete.Enabled = true;
if (rBtn1.Checked)
{
string xpath = "/Contacts/Contact[FullName='" + lstbox1.Text + "']";
XmlNode node = doc.SelectSingleNode(xpath);
txt2.Text = node["FullName"].InnerText; //This is where i get the exception
txt3.Text = node["HomePhone1"].InnerText;
txt4.Text = node["HomePhone2"].InnerText;
txt5.Text = node["MobilePhone1"].InnerText;
txt6.Text = node["MobilePhone2"].InnerText;
txt7.Text = node["HomeAddress"].InnerText;
txt8.Text = node["E-MailAddress"].InnerText;
}
}
Also if someone can tell me how to search in a XML file through a TextBox that would be great. I tried Google but not much results about that.
Screenshot: