I have this problem today...
I have a windows form
this windows form loads an xml document, and when I use the first, next, previous and last buttons, they move between the persons elements, what I want to do is:
when you write something on the txtLastName and you click on the find button (is working good), what I want is to copy those elements of the query into a new xml document...
cause I want the results to be showed in the textboxes, and i need that the first, next, previous and last buttons to make me move between the query elements that are in the new xml document.
here is the code that im using:
private void btnNext_Click(object sender, EventArgs e)
current = (current + 1 > max) ? max : current + 1;
currentPerson = (XmlElement)root.ChildNodes[current];
if (current >= max)
MessageBox.Show("No More Persons in the XML", "Done");
private void btnFind_Click(object sender, EventArgs e)
string keyword = txtLastName.Text;
var NewoXmlDoc = XDocument.Load(@"C:\people2.xml");
var query = NewoXmlDoc.Descendants()
.Where(x => !x.HasElements &&
x.Value.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase) >= 0);
foreach (var element in query)
string uFirstName = element.Parent.Element("FirstName").Value;
string uLastName = element.Value;
txtName.Text = uFirstName;
txtLastName.Text = uLastName;
thanks in advance..!!