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))
{
docxmllist->Load(Filename);
XmlElement ^ elmlistitem = docxmllist->DocumentElement;
XmlNodeList ^ lstxmllist = elmlistitem->ChildNodes;
for each(XmlNode ^ node in lstxmllist)
lbxlistitem->Items->Add(node->FirstChild->InnerText;
}
else
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.