简体   繁体   English

如何将多行文本框绑定到bindingList <string> ?

[英]How to bind multiline textbox to bindingList<string>?

How can I bind textboxt text to BindingList? 如何将textboxt文本绑定到BindingList? I want so that when I add/change/remove string from that BindingList my TextBox will update. 我想要这样,当我从该BindingList添加/更改/删除字符串时,我的TextBox将更新。

Create a single string with line breaks from the List 从列表创建带有换行符的单个字符串

 stringbuilder sb = new stringbuilder();   
 foreach (string s in lstring) sb.AppendLine(s); 

Use BindingSource class to bind a String to a textbox. 使用BindingSource类将字符串绑定到文本框。 All you need is to bind the textbox with BindingSource object, whose data source is the string you want to use. 您所需要做的就是用BindingSource对象绑定文本框,该对象的数据源是您要使用的字符串。

TextBox textBox1 = new TextBox();
BindingSource stringBindingSource;
string x = "ABCDEFGHIJKLMNOP";

stringBindingSource = new System.Windows.Forms.BindingSource(this.components);
textBox1.DataBindings.Add(new Binding("Text",stringBindingSource,"Length",true));
stringBindingSource.DataSource = x;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM