mercredi 11 mars 2015

ListBox.Clear() not clear the items and overwrite on the previous items [on hold]

Here the codes of the problem,i got similar codes on other form with different formules and on the other form listbox.clear() metod work.But on this doesn't.It's for the first run,saving the items in the listboxes but whan i trying to proccess for the second time it's overwrite previous results in textfile.I added if else control for the fix it but couldn't fix again.



if (textBox1.Text != String.Empty && textBox2.Text != String.Empty)
{
double x, y, d, g, l;
d = Convert.ToDouble(textBox1.Text);
l = Convert.ToDouble(textBox2.Text);
for (double i = -5; i <= 1; i += l)
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("en");
Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
x = (d / 3.141) * (i + 1);
x = Math.Round(x, 4);
y = (d / 3.141) * (System.Math.Exp(i) + (3.141 / 2));
y = Math.Round(y, 4);
g = 0;
listBox1.Items.Add(x);
listBox2.Items.Add(y);
listBox3.Items.Add(g);
string Path = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\EnisFormül\\";
if (!Directory.Exists(Path))
{
Directory.CreateDirectory(Path);
}
using (StreamWriter SaveFile = new StreamWriter(Path + textBox1.Text + "_" + textBox2.Text + "Rogowski Electrode" + " .txt"))
for (int a = 0; a < listBox1.Items.Count; a++)
{
string line = String.Format("{0}\n {1}\n {2}\n", listBox1.Items[a], listBox2.Items[a], listBox3.Items[a]);
SaveFile.WriteLine(line);
}
}
if (listBox1.Items != null && listBox2.Items != null && listBox3.Items != null)
{
listBox1.Items.Clear();
listBox2.Items.Clear();
listBox3.Items.Clear();
}
textBox1.Clear();
textBox2.Clear();
}

Aucun commentaire:

Enregistrer un commentaire