C# TextBox多行輸入跟讀取

C# TextBox多行輸入跟多行讀取

這2個做法都會利用到TextBox的Multiline特性

 

多行輸入:

foreach (DataGridViewRow dr in this.dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell cbx = (DataGridViewCheckBoxCell)dr.Cells[0];

                if ((bool)cbx.FormattedValue)
                {
                    string txt1= ((System.Data.DataRowView)(dr.DataBoundItem)).Row.ItemArray[0].ToString().Trim();
                    
                   
                    if (!string.IsNullOrEmpty(txt1))
                    {
                        textBox2.AppendText(txt1+ Environment.NewLine);
                    }
                }
                else
                {
                    
                }
            }

多行讀取:

StringBuilder ReturnMB001 = new StringBuilder();

            for (int i = 0; i < textBox1.Lines.Length; i++)
            {
                ReturnMB001.AppendFormat("'" + textBox1.Lines[i] + "'" + ",");
            }
           

            ReturnMB001.AppendFormat("''");
            return ReturnMB001.ToString(); 

 

 

自我LV~