将文本框绑定到数据视图 [英] Binding a textbox to a dataview

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

问题描述

我有一个绑定到数据视图的文本框,当我更新文本框中的文本时,基础数据集中不会发生任何更改。为什么这个?


任何答案都赞赏,至于由于数据集的底层结构,即很多子表等,我不能使用bindingcontext

解决方案

Paul,


如果您没有使用绑定上下文,那么如何绑定到

数据集? DataBindings集合和BindingContext类绑定在一起,你不可能没有另一个。


你究竟在做什么为了创建数据绑定?

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Paul Slavin" <帕******** @ discussions.microsoft.com>在留言中写道

新闻:B9 ********************************** @ microsof t.com ...

我有一个绑定到数据视图的文本框,当我更新
文本框中的文本时,基础数据集中不会发生任何更改。为什么这个?
任何答案都赞赏,至于由于
数据集的底层结构,即很多子表等,我不能使用bindingcontext



感谢您的回复...更多细节


我绑定到数据视图:


this.rgiDataView = new DataView();

this.rgiDataView.Table = this.ds.Tables [" ATPBlockOrOL"];

this.rgiNormTxtBox。 DataBindings.Add(" text",rgiDataView," RailGapIndicatorId");


我根据同一表单上组合框中当前选中的项目更改文本框中的视图:


this.rgiDataView.RowFilter =" BlockOrOLId =''" + this.blockIdComboBox.SelectedValue +"''" ;;


当我更改组合框中的选项时,文本框中的文本会正确更改,但是当我更改文本时文本框中的更改未反映在数据集中。我做的事情基本上是错误的吗?


如果我做同样的事情但是绑定到数据网格而不是文本框它会正确地更新数据集

" Nicholas Paldino [.NET / C#MVP]"写道:

Paul,

如果你没有使用绑定上下文,那么你如何绑定到
数据集? DataBindings集合和BindingContext类绑在一起,你不可能没有另一个。

你究竟在做什么来创建数据绑定?

-
- Nicholas Paldino [.NET / C#MVP]
- mv * @ spam.guard.caspershouse.com

Paul Slavin <帕******** @ discussions.microsoft.com>在消息中写道
新闻:B9 ********************************** @ microsof t.com。 ..

我有一个绑定到数据视图的文本框,当我更新


文本框中的文本时,基础数据集中不会发生任何更改。为什么这个??


任何答案都会受到赞赏,至于由于


数据集的底层结构,即很多子表等,我无法使用bindingcontext




Paul,

检查文本框中的值时,您是否离开了

文本框的焦点?在焦点丢失之前,该值不会被写入数据集(更具体地说,当验证完成时,通常会在焦点丢失时发生
)。 />
-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Paul Slavin" <帕******** @ discussions.microsoft.com>在留言中写道

新闻:1C ********************************** @ microsof t.com ...

感谢您的回复...更多细节

我绑定到数据视图:
this.rgiDataView = new DataView();
this.rgiDataView.Table = this.ds.Tables [" ATPBlockOrOL"];
this.rgiNormTxtBox.DataBindings.Add(" text",rgiDataView ,
" RailGapIndicatorId");
我根据同一表单上组合框中当前所选项目
更改文本框中的视图:
this.rgiDataView.RowFilter =" BlockOrOLId =''" +
this.blockIdComboBox.SelectedValue +"''" ;;
当我更改组合框中的选项时,文本框
中的文本会正确更改,但是当我更改文本时文本框中的更改不是
反映在数据集中。我做的事情基本上是错误的吗?
如果我做同样的事情,但绑定到数据网格而不是
文本框,它会正确更新数据集

Nicholas Paldino [。 NET / C#MVP]"写道:

Paul,

如果您没有使用绑定上下文,那么如何绑定数据集
? DataBindings集合和BindingContext类
绑在一起,你不可能没有另一个。

你究竟在做什么来创建数据绑定?

-
- Nicholas Paldino [.NET / C#MVP]
- mv * @ spam.guard.caspershouse.com

Paul Slavin <帕******** @ discussions.microsoft.com>在消息中写道
新闻:B9 ********************************** @ microsof t.com。 ..

我有一个绑定到数据视图的文本框,当我更新


文本框中的文本时,基础数据集中不会发生任何更改。为什么这个??


任何答案都会受到赞赏,至于由于


数据集的底层结构,即很多子表等,我无法使用bindingcontext




I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this??

any answers appreciated, as to due to the underlying structure of the datasets, i.e lots of child tables etc, I cannot use bindingcontext

解决方案

Paul,

If you are not using binding context, then how are you binding to the
data set? The DataBindings collection and the BindingContext classes are
tied together, and you can''t really have one without the other.

What exactly are you doing in order to create a data binding?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Slavin" <Pa********@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...

I have a textbox bound to a dataview, when I update the text in the textbox no changes take place in the underlying dataset. Why is this??
any answers appreciated, as to due to the underlying structure of the datasets, i.e lots of child tables etc, I cannot use bindingcontext



thanks for your reply... heres a bit more detail

I''m binding to a dataview:

this.rgiDataView = new DataView();
this.rgiDataView.Table = this.ds.Tables["ATPBlockOrOL"];
this.rgiNormTxtBox.DataBindings.Add( "text", rgiDataView, "RailGapIndicatorId" );

and I change the view in the textbox based on the currently selected item in a combobox on the same form:

this.rgiDataView.RowFilter = "BlockOrOLId = ''" + this.blockIdComboBox.SelectedValue + "''";

when I change the selection in the combobox, the text in the text box changes correctly, but when I change text in the textbox the changes aren''t reflected in the dataset. Am I doing something fundamentaly wrong?

If I do exactly the same thing but binding to a datagrid rather than the textbox it updates the dataset correctly
"Nicholas Paldino [.NET/C# MVP]" wrote:

Paul,

If you are not using binding context, then how are you binding to the
data set? The DataBindings collection and the BindingContext classes are
tied together, and you can''t really have one without the other.

What exactly are you doing in order to create a data binding?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Slavin" <Pa********@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...

I have a textbox bound to a dataview, when I update the text in the


textbox no changes take place in the underlying dataset. Why is this??


any answers appreciated, as to due to the underlying structure of the


datasets, i.e lots of child tables etc, I cannot use bindingcontext




Paul,

When checking the value in the textbox, have you left the focus of the
textbox? The value will not be written to the dataset until the focus is
lost (more specifically, when validation is complete, which usually happens
when focus is lost).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Slavin" <Pa********@discussions.microsoft.com> wrote in message
news:1C**********************************@microsof t.com...

thanks for your reply... heres a bit more detail

I''m binding to a dataview:

this.rgiDataView = new DataView();
this.rgiDataView.Table = this.ds.Tables["ATPBlockOrOL"];
this.rgiNormTxtBox.DataBindings.Add( "text", rgiDataView, "RailGapIndicatorId" );
and I change the view in the textbox based on the currently selected item in a combobox on the same form:
this.rgiDataView.RowFilter = "BlockOrOLId = ''" + this.blockIdComboBox.SelectedValue + "''";
when I change the selection in the combobox, the text in the text box changes correctly, but when I change text in the textbox the changes aren''t
reflected in the dataset. Am I doing something fundamentaly wrong?
If I do exactly the same thing but binding to a datagrid rather than the textbox it updates the dataset correctly

"Nicholas Paldino [.NET/C# MVP]" wrote:

Paul,

If you are not using binding context, then how are you binding to the data set? The DataBindings collection and the BindingContext classes are tied together, and you can''t really have one without the other.

What exactly are you doing in order to create a data binding?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Paul Slavin" <Pa********@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...

I have a textbox bound to a dataview, when I update the text in the


textbox no changes take place in the underlying dataset. Why is this??


any answers appreciated, as to due to the underlying structure of the


datasets, i.e lots of child tables etc, I cannot use bindingcontext




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

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