I am having a problem with formatting the output from foreach loop. What should I do to format output as showed below the code? I am currently using following code:
foreach (AddEntry list in addedEntry)
{
// Displaying and formating the output in text box in MainWindow.
mainWindow.ChangeTextBox += list.Type + Environment.NewLine;
if (cmbType.SelectedIndex == 1)
mainWindow.ChangeTextBox += "URL: " + list.URL + Environment.NewLine;
if (cmbType.SelectedIndex == 2)
mainWindow.ChangeTextBox += "Software Name: " + list.SoftwareName + Environment.NewLine;
if (cmbType.SelectedIndex == 2)
mainWindow.ChangeTextBox += "Serial Code: " + list.SerialCode + Environment.NewLine;
if (cmbType.SelectedIndex == 0 || cmbType.SelectedIndex == 1)
mainWindow.ChangeTextBox += "User Name: " + list.UserName + Environment.NewLine;
if (cmbType.SelectedIndex == 0 || cmbType.SelectedIndex == 1)
mainWindow.ChangeTextBox += "Password: " + list.Password + Environment.NewLine;
mainWindow.ChangeTextBox += Environment.NewLine;
}
First output:
PC Password
User Name: a
Password: b
Then adding another entry...
Second output:
PC Password
URL: e // this should not be here
User Name: a
Password: b
Web Site Password
URL: www.
User Name: www
Password: www
Second output should be:
PC Password
User Name: a
Password: b
Web Site Password
URL: www.
User Name: www
Password: www
Hope for some tips.
Regards.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…