Hey I am trying to have a combo box read the first child node in my xml file and formulate a list on that. Everything I keep seeing relates to C# and thus doesn't work very well.

I was originally thinking of doing this by doing an event on the combo box....so something like this:

this->combobox1->Items->AddRange += gcnew System::EventHandler(this, &form1::combobox1_Range);

followed with something along these lines:

#pragma endregion
private: System::Void combobox1_Range(System::Object^ sender, System::EventArgs^ e) {
     String ^ Filename = L"xml.xml";
     XmlDocument ^ docxmllist = gcnew XmlDocument;

     if (File::Exists(Filename))
          XmlElement ^ elmlistitem = docxmllist->DocumentElement;
          XmlNodeList ^ lstxmllist = elmlistitem->ChildNodes;

          for each(XmlNode ^ node in lstxmllist)
     MessageBox::Show(L"An error occurred");

This isn't working, so can someone please explain why? I mean in theory it should work in my mind because when your dropping down the list it is calling the event to ask for the xml file. Maybe my rationale is off on this. I don't necessarily need the solution but an explanation would be a 1000 times better.

I am just beginning to play with xml and cli/c++ so please be gentle. Thank you everyone.

If you add a reference to System.Xml.Linq int your project and include the namespace:

using namespace System::Xml::Linq;

You can use an easier set of xml classes stemming from XDocument.

XDocument^ xd = XDocument::Load("c:/science/zuba_sheet.xml");
    //Write all nodes
    for each(XNode^ xn in xd->Nodes())

Then you can have an easier time reaching XElements and XNodes.
You should load the XML once outside of the combobox functions, so when you need it, you'll have it quickly.

Be a part of the DaniWeb community

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