数据表添加新行 [英] Datatable add new row

查看:133
本文介绍了数据表添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个带有一个标签和几个文本框的表单.这些控件具有与DataTable"myTable"的数据绑定.
单击添加新"按钮后,所有带有数据的控件均为空.我需要保留标签的值.有可能吗?

以下是更多详细信息:

SelectCommand:

Hi
I have a form with one label and few textboxes. These controls have data bindings with DataTable "myTable".
After "Add New" button click, the all controls with data are empty. I need to preserve the value of the label. Is that possible ?

Here are more details:

SelectCommand:

SELECT t1.FieldX, t2.FieldA, t2.FieldB
FROM table1 t1
JOIN table2 t2 on t2.FieldY = t1.FieldX



数据绑定:



Data binding:

LABEL.DataBindings.Add("Text", myTable, "FieldX")
TEXTBOX1.DataBindings.Add("Text", myTable, "FieldA")
TEXTBOX2.DataBindings.Add("Text", myTable, "FieldB")




添加新"按钮单击事件中的部分代码:




Part of code at "Add New" button click event :

// insert data to database table table2 
...
BindingContext(myTable).EndCurrentEdit()
BindingContext(myTable).AddNew()
// after that all values are empty
// need to preserve label value
...

推荐答案

如果您希望所有控件都绑定到保存记录,那么不能,则不能保留标签的内容.

但是,如果标签是由其自己的BindingContext绑定的,则可以具有多组绑定,而不是将所有控件都绑定到同一记录的default表单.
If you expect all the controls to be bound to the save record, then no, you cannot preserve the contents of the label.

But, if the label was being bound by its own BindingContext, then you can have multiple sets of bindings instead of the forms default where all the controls are bound to the same record.


这篇关于数据表添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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