I am trying to get the message box to show the elements but messagebox will not pop when I run the application
string xml = @"<?xml version='1.0' encoding='UTF-8'?>
<widgets>
<widget>
<url>~/Portal/Widgets/ServicesList.ascx</url>
<castAs>ServicesWidget</castAs>
<urlType>ascx</urlType>
<parameters>
<PortalCategoryId>3</PortalCategoryId>
</parameters>
</widget>
<widget>
<url>www.omegacoder.com</url>
<castAs>ServicesWidget</castAs>
<urlType>htm</urlType>
<parameters>
<PortalCategoryId>41</PortalCategoryId>
</parameters>
</widget>
</widgets>";
XDocument loaded = XDocument.Parse( xml );
var widgets = from x in loaded.Descendants( "widget" )
select new
{
URL = x.Descendants( "url" ).First().Value,
Category = x.Descendants( "PortalCategoryId" ).First().Value
};
MessageBox.Show("one");
foreach ( var wd in widgets ){
MessageBox.Show("two");
}
MessageBox.Show(“one”); shows up.
MessageBox.Show(“two”); never pops up
Also what if I wanna see a count of widgets> I am new to C#
thanks
You can replace your LINQ query with:
UPDATE:
Both versions of LINQ should work correctly. My mistake, Descendants can point not only to directly nested nodes, but to all the nodes in the subtree.
Probable issue cause:
However, be aware that in order to show the second message box, you have to close the first one. I’ve just tested this and it worked.
Suggested solution:
In order to be available to show multiple dialogs with messages, you can just create your own form class in the project, instantiate it and show it with Show() method i.e.:
you can add a new Windows Form, call it MessageForm and use the following code:
It should work as intended then.