c#文本框不显示所有内容

New*_*ser 0 c# wpf textbox

我想要一个显示单词Seq(这是一个列名)的文本框,然后列出其下面的mylist中的值.到目前为止,列表中的值显示,但Seq没有显示

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

          }
Run Code Online (Sandbox Code Playgroud)

Ann*_* L. 5

您将值重新分配给值textBox1.Text列表,而不是将值列表附加到文本框内容.

试试这个:

 textBox1.Text = " Seq"; // This guy doesn't showup in the textbox
 textBox1.Text += Environment.NewLine + String.Join(Environment.NewLine, SeqIrregularities);
Run Code Online (Sandbox Code Playgroud)

如果你正在做的是创建它们的连接字符串,你也不需要遍历你的违规行为.

另一种方法(可能更清楚):

string irregularities = String.Join(Environment.NewLine, SeqIrregularities);
string displayString = " Seq" + Environment.NewLine + irregularities;
textBox1.Text = displayString;
Run Code Online (Sandbox Code Playgroud)