![](/img/trans.png)
[英]How to bind TextBox.Lines to BindingList<string> in WinForms in C#?
[英]How to bind multiline textbox to bindingList<string>?
如何將textboxt文本綁定到BindingList? 我想要這樣,當我從該BindingList添加/更改/刪除字符串時,我的TextBox將更新。
從列表創建帶有換行符的單個字符串
stringbuilder sb = new stringbuilder();
foreach (string s in lstring) sb.AppendLine(s);
使用BindingSource類將字符串綁定到文本框。 您所需要做的就是用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.