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 ;)