-
April 3rd, 2011, 08:43 AM
#1
Diplaying an arraylist from an xml in a Dialog MessageBox
Hi everyone, my first time posting in this forum. Glad to see that it exists! Here is my problem:
I am creating a program that reads from an xml file and then displays that information in a Dialog MessageBox. The program is designed to kill running processes. I am using Visual Studio Professional 2010 and programming in C#.
I want the MessageBox to come up immediately when the program runs (which it does) so I put it in the Form1_Load. Then entire program runs well except I can't display the arraylist in the MessageBox without getting errors. Any and all suggestions would be welcome. Thanks for looking. Here is the code:
NOTE: oReadXML is the arraylist. I have commented it out in the code as you will notice in order to run the program and test that everything else works.
private void Form1_Load(object sender, EventArgs e)
{
//displays arraylist in a dialog messagebox
DialogResult dlgResult = MessageBox.Show(/*oReadXML.ToString(),*/ "Do you wish to kill these processes?",
"Continue", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{
//kills the processes listed
oGetProcesses.Locate_Kill_Process(oReadXML.ToString());
}
else
{
}
}
-
April 3rd, 2011, 04:39 PM
#2
Re: Diplaying an arraylist from an xml in a Dialog MessageBox
Calling ToString() on an ArrayList will simply return "System.Collections.ArrayList", it won't nicely print every element inside of the collection.
First, don't use an ArrayList at all, use a strongly typed generic collection. There is seldom a good reason to use an ArrayList since the days of .NET 2.0 and I don;t know why people still insist on using them.
Second, if you want to print a chunk of XML then format it yourself or load it into an XmlDocument first.
-
April 4th, 2011, 08:13 AM
#3
Re: Diplaying an arraylist from an xml in a Dialog MessageBox
Thanks for the reply BigEd. I have to use an Arraylist because I am doing this as a project for school and it is required (but thanks for the info though)
I think I got it down except for one small problem. New code is posted below (I put it inside a foreach loop) but now I get an error on the foreach.
the error reads: Error 1 foreach statement cannot operate on variables of type 'Process_Killer.Read_XML_Class' because 'Process_Killer.Read_XML_Class' does not contain a public definition for 'GetEnumerator'
Process_Killer is the name of my program
Read_XML_Class is obviously the name of the class with the code to read the xml
Don't understand enough to know why I am getting this error.
any suggestions and help are appreciated.
private void Form1_Load(object sender, EventArgs e)
{
string stringmine;
foreach (string strProcess in oReadXML)
{
stringmine = strProcess;
//displays arraylist in a dialog messagebox
DialogResult dlgResult = MessageBox.Show(stringmine + "Do you wish to kill these processes?",
"Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (dlgResult == DialogResult.Yes)
{
//kills the processes listed
oGetProcesses.Locate_Kill_Process(oReadXML.ToString());
}
else
{
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|