读书人

textbox.lins=new string[]的有关问题

发布时间: 2012-03-21 13:33:15 作者: rapoo

textbox.lins=new string[]的问题?
代码如下: this.textBox2.Lines = new String[10];
for (int i=0;i<10;i++)
{
this.textBox2.Lines[i]=Convert.ToString(i);
}
这样的在textbox中发现产生了多个行,但是每行都是空的,没有数据.
但是如下却可以显示:

String[] strs = new String[10];

for (int i=0;i<10;i++)
{
strs[i]=Convert.ToString(i);
}
this.textBox2.Lines = strs;

为什么?请高手指点

[解决办法]
见帮助,在默认情况下,行的集合是 TextBox 中的行的只读副本。若要获取可写行集合,请使用与下面的代码相似的代码:textBox1.Lines = new string[] { "abcd" };

[解决办法]
老兄:
我在 System.Web.UI.WebControl.TextBox 和 System.Windows.Form.TextBox 中都没有看到 Lines 这个属性!!

我很想知道你的 textBox2 到底是什么控件!!

——换言之:你的这个控件可能内部代码 控制了不允许你 给子元素赋值!
[解决办法]
代码如下: this.textBox2.Lines = new String[10];
for (int i=0;i<10;i++)
{
this.textBox2.Lines[i]=Convert.ToString(i);
}
按时因为你没有个String复制啊

C# code
 //this.textBox2.Lines是string[] this.textBox2.Lines = new String[3]{"abc","cde","fgh"};
[解决办法]
C# code
public string[] Lines{    get    {        string text = this.Text;        ArrayList arrayList = new ArrayList();        int j;        for (int i = 0; i < text.Length; i = j)        {            for (j = i; j < text.Length; j++)            {                char c = text[j];                if (c == '\r' || c == '\n')                {                    break;                }            }            string value = text.Substring(i, j - i);            arrayList.Add(value);            if (j < text.Length && text[j] == '\r')            {                j++;            }            if (j < text.Length && text[j] == '\n')            {                j++;            }        }        if (text.Length > 0 && (text[text.Length - 1] == '\r' || text[text.Length - 1] == '\n'))        {            arrayList.Add("");        }        return (string[])arrayList.ToArray(typeof(string));    }    set    {        if (value != null && value.Length > 0)        {            StringBuilder stringBuilder = new StringBuilder(value[0]);            for (int i = 1; i < value.Length; i++)            {                stringBuilder.Append("\r\n");                stringBuilder.Append(value[i]);            }            this.Text = stringBuilder.ToString();            return;        }        this.Text = "";    }} 

读书人网 >C#

热点推荐