I want to have a textbox that displays the word Seq (which is a column name), then lists values from mylist underneath it. So far, the values from the list show up but the word Seq doesn't
private void button7_Click(object sender, EventArgs e)
{
if (seq1)
{
textBox1.Text = " Seq"; // This guy doesn't showup in the textbox
foreach (object o in SeqIrregularities)
{
textBox1.Text = String.Join(Environment.NewLine, SeqIrregularities);
}
}
}
You're reassigning the value of textBox1.Text
to your list of values, rather than appending the list of values to the textbox contents.
Try this:
textBox1.Text = " Seq"; // This guy doesn't showup in the textbox
textBox1.Text += Environment.NewLine + String.Join(Environment.NewLine, SeqIrregularities);
You also don't need to loop through your irregularities if what you're doing is creating a concatenated string of them.
Another way to do it (which may be clearer):
string irregularities = String.Join(Environment.NewLine, SeqIrregularities);
string displayString = " Seq" + Environment.NewLine + irregularities;
textBox1.Text = displayString;
change your code to this:
private void button7_Click(object sender, EventArgs e)
{
if (seq1)
{
textBox1.Text = " Seq"; // This guy doesn't showup in the textbox
foreach (object o in SeqIrregularities)
{
textBox1.Text += String.Join(Environment.NewLine, SeqIrregularities);
}
}
}
You were overwriting your text in each iteration of your foreach-statement. You have to use +=
instead of =
in your foreach-statement.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.