Hi,

in part of my app I have to load an XML file and read an Attribute from it to output in a MessageBox.

The MessageBox is called from a click event on a DataGridView.

The way I have the code below I get an error that my INT gSize is not found:-

XmlDocument xDocID = new XmlDocument();
xDocID.Load(System.IO.Path.Combine(Application.StartupPath, "img" + i + ".xml"));	
XmlNodeList imgSize = xDocID.GetElementsByTagName("size");
            
for(int gSize = 0; gSize < imgSize.Count; ++ gSize)
{
dGV.Rows.Add(imgSize[gSize].Attributes["width"].Value + " x " + imgSize[gSize].Attributes["height"].Value, imgSize[gSize].Attributes["label"].Value, "GO");
}
dGV.CellContentClick += delegate(object s, DataGridViewCellEventArgs e3)
            	 {
	        if (e3.ColumnIndex ==2){
		MessageBox.Show(imgSize[gSize].Attributes["source"].Value);
		};}

Now, I have fiddled around a bit and sort of figured out that the problem is because the INT is outside of the LOOP, so, here is another attempt:

XmlDocument xDocID = new XmlDocument();
xDocID.Load(System.IO.Path.Combine(Application.StartupPath, "img" + i + ".xml"));	
XmlNodeList imgSize = xDocID.GetElementsByTagName("size");
            
for(int gSize = 0; gSize < imgSize.Count; ++ gSize)
{
dGV.Rows.Add(imgSize[gSize].Attributes["width"].Value + " x " + imgSize[gSize].Attributes["height"].Value, imgSize[gSize].Attributes["label"].Value, "GO");
string img_source = imgSize[gSize].Attributes["source"].Value;
}
dGV.CellContentClick += delegate(object s, DataGridViewCellEventArgs e3)
            	 {
	        if (e3.ColumnIndex ==2){
		MessageBox.Show(img_source);
		};}

I have made a string within the LOOP and called this in the MessageBox.

This however does not work correctly.

It displays the MessageBox over and over until the INT reaches it's maximum value.

Does anyone have any ideas about resolving this?

Kind regards..,

MT ;)

Hi,

in part of my app I have to load an XML file and read an Attribute from it to output in a MessageBox.

The MessageBox is called from a click event on a DataGridView.

The way I have the code below I get an error that my INT gSize is not found:-

XmlDocument xDocID = new XmlDocument();
xDocID.Load(System.IO.Path.Combine(Application.StartupPath, "img" + i + ".xml"));	
XmlNodeList imgSize = xDocID.GetElementsByTagName("size");
            
for(int gSize = 0; gSize < imgSize.Count; ++ gSize)
{
dGV.Rows.Add(imgSize[gSize].Attributes["width"].Value + " x " + imgSize[gSize].Attributes["height"].Value, imgSize[gSize].Attributes["label"].Value, "GO");
}
dGV.CellContentClick += delegate(object s, DataGridViewCellEventArgs e3)
            	 {
	        if (e3.ColumnIndex ==2){
		MessageBox.Show(imgSize[gSize].Attributes["source"].Value);
		};}

Now, I have fiddled around a bit and sort of figured out that the problem is because the INT is outside of the LOOP, so, here is another attempt:

XmlDocument xDocID = new XmlDocument();
xDocID.Load(System.IO.Path.Combine(Application.StartupPath, "img" + i + ".xml"));	
XmlNodeList imgSize = xDocID.GetElementsByTagName("size");
            
for(int gSize = 0; gSize < imgSize.Count; ++ gSize)
{
dGV.Rows.Add(imgSize[gSize].Attributes["width"].Value + " x " + imgSize[gSize].Attributes["height"].Value, imgSize[gSize].Attributes["label"].Value, "GO");
string img_source = imgSize[gSize].Attributes["source"].Value;
}
dGV.CellContentClick += delegate(object s, DataGridViewCellEventArgs e3)
            	 {
	        if (e3.ColumnIndex ==2){
		MessageBox.Show(img_source);
		};}

I have made a string within the LOOP and called this in the MessageBox.

This however does not work correctly.

It displays the MessageBox over and over until the INT reaches it's maximum value.

Does anyone have any ideas about resolving this?

Kind regards..,

MT ;)

Got it! Hooray!

I created another column in the DataGridView into which I loaded the data from the XML file.

I made this new column HIDDEN and then called the content value in the MessageBox, see below:-

for(int gSize = 0; gSize < imgSize.Count; ++ gSize)
        {
        	string imgWidth = imgSize[gSize].Attributes["width"].Value;
        	string imgHeight = imgSize[gSize].Attributes["height"].Value;
        	string imgLabel = imgSize[gSize].Attributes["label"].Value;
        	string imgSource = imgSize[gSize].Attributes["source"].Value;
        	dGV.Rows.Add(imgWidth + " x " + imgHeight, imgLabel, "GO", imgSource);
        }
     dGV.CellContentClick += delegate(object s, DataGridViewCellEventArgs e3)
            	 {
	string RtextIn = dGV.Rows[e3.RowIndex].Cells[e3.ColumnIndex+1].FormattedValue.ToString();
	
	    if (e3.ColumnIndex ==2){
		MessageBox.Show(RtextIn);
		};

Regards..,

MT :)

Be a part of the DaniWeb community

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