在多行文本框上逐行显示文本

本文关键字:文本 逐行 显示 | 更新日期: 2023-09-27 18:15:26

嗨,伙计们,当我检索我的数据从访问数据库到我的文本框多行文本框的数据是显示一个旁边一个我想要任何行在它的行,例如,我有5行在我的访问字段,但在我的文本框显示所有的数据在同一行我应该做什么,请提供任何帮助?

OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "''db''it.accdb");
con.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from data where [ID] like(" + textBox9.Text + ")";
cmd.Connection = con;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
    textBox1.Text = reader["Name"].ToString();
    textBox20.Text = reader["Description"].ToString();
    // ----------------------------------------------
    // These doesn't work with me :
    // ----------------------------------------------
    //textBox2.Text = Environment.NewLine;
    //textBox28.Text = textBox28.Text + Environment.NewLine;
    //textBox2.Text = textBox28.Text + Environment.NewLine;
}
con.Close();

在多行文本框上逐行显示文本

try this,

textBox1.Multiline = true;
textBox1.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox1.AcceptsReturn = true;
textBox1.WordWrap = true;
textBox20.Multiline = true;
textBox20.ScrollBars = ScrollBars.Vertical;//Other settings is Horizontal and Both
textBox20.AcceptsReturn = true;
textBox20.WordWrap = true;
while (reader.Read())
{
    textBox1.Text += reader["Name"].ToString() + Environment.NewLine;
    textBox20.Text += reader["Description"].ToString() + Environment.NewLine;
}

使用字符串'新行字符' "'n"创建新行。这样的:

textBox1.Text = reader["Name"].ToString() + "'n";
textBox20.Text = reader["Description"].ToString() + "'n";