iItem nItem = new iItem("abc");//数据源,text是它的属性PictrueBox box = new PictrueBox(); //控件box.DataBindings.Add(new System.Windows.Forms.Binding("Name", nItem, "text", true));怎么没有绑定好啊?请问为什么?谢谢

解决方案 »

  1.   

    iItem是我定义的一个类。
    class iItem
    {
            private string textname;
            public iItem(string tt)
            {
               text = tt;
            }
            public string text
            {
                get { return textname; }
                set { textname = value; }
            }}
      

  2.   

    没什么问题...只不过在你绑定之前必须将PictureBox添加到Form上...try..iItem nItem = new iItem("abc");
                PictureBox box = new PictureBox();
                this.Controls.Add(box);
                box.DataBindings.Add(new System.Windows.Forms.Binding("Name", nItem, "text", true));
                //测试一下
                this.textBox1.Text = box .Name;
      

  3.   

    this.Controls.Add(box);这句话我加进去,也没有用阿
      

  4.   

    我测试是可以的...TextBox中显示"abc"..你是怎么知道没有用的?
      

  5.   

    PictureBox box = new PictureBox();
                this.Controls.Add(box);
                box.DataBindings.Add("Name", nItem, "text", true);
    就这样的代码,如果有用的话,box.Name应该是有值得,可是调试到后面,还是空
      

  6.   

    是有值的啊..你和我一样,用一个TextBox测试一下看看...iItem nItem = new iItem("abc");
                PictureBox box = new PictureBox();
                this.Controls.Add(box);
                box.DataBindings.Add(new System.Windows.Forms.Binding("Name", nItem, "text", true));
                //测试一下
                this.textBox1.Text = box .Name;
      

  7.   

    晕,我用TextBox也不行,真是奇怪啊
      

  8.   

    我就奇怪了...要不你这样做个测试...新建一个项目,在Form上就只放一个TextBox和一个Button,在Button的单击事件下,将我上面写的代码加进去,再测试一下看....如果这样也不行,那我就没话说了...