将DataTable绑定到Textbox UserControl [英] Bind DataTable To Textbox UserControl

查看:77
本文介绍了将DataTable绑定到Textbox UserControl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多这个问题,但我没有找到任何明确的帖子。



我用这个命令进行数据绑定:



 userControl11.DataBindings.Clear(); 
userControl1.DataBindings.Add( Text,dt, DM);





这项工作适用于常用控件,但不适用于用户控件。



现在,如果我选择不同的datagridview行并且它总是为空的,则usercontrol的文本不会改变。 />


我应该使用

 INotifyPropertyChanged 

吗?

解决方案

我知道答案很简单!



我只是在Usercontrol中这样做:



< pre lang =c#> public 覆盖 string Text
{
get { return txtmoney.Text; }
set
{

txtmoney.Text = value ;

}
}



这个以我的形式绑定:



 uctextbox1.DataBindings.Add(  text,DT,  DM); 


I searched a lot for this problem but i did not find any clear post about that.

I do databinding with this command:

userControl11.DataBindings.Clear();
userControl1.DataBindings.Add( "Text",dt,"DM" );



this work for usual controls but not for usercontrols.

Now the Text of the usercontrol does not change if i select different rows of datagridview and it is always empty.

Should I use

INotifyPropertyChanged

for this ?

解决方案

I knew the answer is simple!

simply I did this in Usercontrol :

public override string Text
   {
       get { return txtmoney.Text; }
       set
       {

           txtmoney.Text = value;

       }
   }


And this to bind in my form :

uctextbox1.DataBindings.Add( "text",DT,"DM" );


这篇关于将DataTable绑定到Textbox UserControl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆