ComboBox数据绑定问题 [英] ComboBox databindng Problem

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

问题描述

ComboBox databindng问题


==如何设置和使用ComboBox:

我的comboBox由查找表填充。 ValueMember是

查找表的Id,DisplayMember是查询表中

对应字段的文本。在我的数据表中,我们将

ID存储在我称之为密钥的字段中。


==所需操作的描述:


1.)当用户选择数据网格中的记录时,绑定的组合框

显示存储在
$ b中的相应值的DisplayMember $ b数据表'''key''字段。

2.)当用户选择''key''字段为空的记录时(否

选择已经制作或保存)comboBox显示应该是空的

表示事实。


==问题描述:


简单地说,上面的#2不会发生。这是做什么的;当用户

移动到数据网格中'key字段为空的记录时,

组合框是*不*为空,它会错误地显示第一个可能

在comboBox中选择。


==其他事实:(仔细阅读 - 这可能有点

令人困惑)


考虑一个场景,其中第一条记录在''key''

字段和第二和第三条记录中存储一个值' 'key''字段为空。

以下是我们浏览记录时发生的情况;

在第1条记录中:comboBox始终显示正确的值

对应于''key''字段。

当用户移动到第二条记录时:错误 - 显示的值是
而不是空的。

当用户移动到第3条记录时:正确 - 显示组合框

为空。

当用户移回第2条记录时:正确 - c omboBox是这次显示为空的



总结 - 当你从一个带有填充''键''的记录移动到
带有''key''字段的
记录 - 显示不正确的值*总是*

。当你从具有空''key''字段的记录移动到具有空''key'字段的另一个

记录时 - 正确a * blank *将*总是*是

显示在comboBox中。带有填充的''键''记录的记录将

*始终显示正确的值。


显示行为错误的原因是什么?

获得正确显示行为的解决方案是什么?


======================= =

BTW - 这是我填充和绑定控件的顺序和

datagrid。

1.)用数据集填充数据集数据网格的数据表,控件

和组合框

2.)设置组合框数据源,值和显示成员

3.)设置datagrid datasource和datamember

4.)将控件绑定到数据表和相应的字段

5.)将绑定上​​下文设置为数据表

ComboBox databindng Problem

== How the ComboBox is setup and used:

My comboBox is populated by a lookup table. The ValueMember is the
lookup table''s Id and the DisplayMember is the text from a
corresponding field in the lookup table. In my data table we store the
ID in what I will call the ''key'' field.

== Description of the desired operation:

1.) When the user selects a record in the datagrid the bound comboBox
displays the DisplayMember of the corresponding Value stored in the
data table''s ''key'' field.
2.) When the user selects a record in where the ''key'' field is null (no
selection was made or saved) the comboBox display should be empty to
indicated that fact.

== Description of the problem:

Simply put, #2 above does not happen. Here is what does; When the user
moves to a record in the datagrid in which the ''key'' field is null the
comboBox is *not* empty, it incorrectly displays the first possible
selection in the comboBox.

== Additional facts: (read carefully - this could be a little
confusing)

Consider a scenario in which the 1st record stores a value in the ''key''
field and in the 2nd and 3rd records in which the ''key'' field is null.
Here is what happens when we walk through the records;
In the 1st record: the comboBox always displays the correct value
corresponding to the ''key'' field.
As the user moves to the 2nd record: incorrectly - values are shown
rather than being empty.
As the user moves to the 3rd record: correctly - the comboBox is shown
empty.
As the user moves back to the 2nd record: correctly - the comboBox is
shown empty this time.

In summary - when you move from a record with a populated ''key'' to a
record with a null ''key'' field - incorrect values will *always* be
displayed. When you move from record with a null ''key'' field to another
record with a null ''key'' field - correctly a *blank* will *always* be
displayed in the comboBox. Records with a populated ''key'' filed will
*always display correct values.

What is the reason for the wrong display behavior?
What is the solution to get proper display behavior?

========================
BTW - Here is the order in which I populate and bind the controls and
datagrid.
1.) populate the dataset with the datatables for the datagrid, controls
and the combobox
2.) set the combobox datasource, value and display members
3.) set the datagrid datasource and datamember
4.) bind the controls to the datatable and corresponding field
5.) set the binding context to the datatable

推荐答案




" dbuchanan" <分贝********* @ hotmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
Hi,

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
ComboBox数据绑定问题

==如何设置和使用ComboBox:

我的comboBox由查找表填充。 ValueMember是
查找表的Id,DisplayMember是查找表中
对应字段的文本。在我的数据表中,我们将
ID存储在我称之为键的字段中。

==所需操作的描述:

1 。)当用户选择数据网格中的记录时,绑定的组合框
显示存储在
数据表的''键'字段中的相应值的DisplayMember。
2。当用户选择'key字段为空(没有选择或保存)的记录时,comboBox显示应该为空以表示该事实。

==问题描述:

简单地说,上面的#2没有发生。这是做什么的;当用户移动到数据网格中'key字段为空的记录时,
组合框不是*为空,它会错误地显示第一个可能的选项。 comboBox。

==其他事实:(仔细阅读 - 这可能有点令人困惑)

考虑第一条记录存储值的情况''key''
字段以及''key''字段为空的第2和第3条记录。
这是当我们浏览记录时会发生的事情;
In第一条记录:组合框始终显示与键字段对应的正确值。
当用户移动到第二条记录时:错误 - 显示值而不是当用户移动到第3条记录时:正确 - 组合框显示为空。
当用户移回第2条记录时:正确 - 组合框是
这次显示为空。

总之 - 当你移动时e从带有填充''键''的记录到带有空''key''字段的
记录 - 将显示不正确的值*总是*显示。当您从具有空键字段的记录移动到具有空键字段的另一个
记录时 - 正确地*空白*将*总是*将显示在组合框中。带有填充的钥匙记录的记录将始终显示正确的值。

错误的显示行为是什么原因?
什么是正确的解决方案显示行为?

========================
BTW - 这是我填写的顺序和绑定控件和
datagrid。
1.)使用数据表格填充数据集,控件
和组合框
2.)设置组合框数据源,值和显示成员
3.)设置datagrid数据源和数据库
4.)将控件绑定到数据表和相应的字段
5.)将绑定上​​下文设置为数据表
ComboBox databindng Problem

== How the ComboBox is setup and used:

My comboBox is populated by a lookup table. The ValueMember is the
lookup table''s Id and the DisplayMember is the text from a
corresponding field in the lookup table. In my data table we store the
ID in what I will call the ''key'' field.

== Description of the desired operation:

1.) When the user selects a record in the datagrid the bound comboBox
displays the DisplayMember of the corresponding Value stored in the
data table''s ''key'' field.
2.) When the user selects a record in where the ''key'' field is null (no
selection was made or saved) the comboBox display should be empty to
indicated that fact.

== Description of the problem:

Simply put, #2 above does not happen. Here is what does; When the user
moves to a record in the datagrid in which the ''key'' field is null the
comboBox is *not* empty, it incorrectly displays the first possible
selection in the comboBox.

== Additional facts: (read carefully - this could be a little
confusing)

Consider a scenario in which the 1st record stores a value in the ''key''
field and in the 2nd and 3rd records in which the ''key'' field is null.
Here is what happens when we walk through the records;
In the 1st record: the comboBox always displays the correct value
corresponding to the ''key'' field.
As the user moves to the 2nd record: incorrectly - values are shown
rather than being empty.
As the user moves to the 3rd record: correctly - the comboBox is shown
empty.
As the user moves back to the 2nd record: correctly - the comboBox is
shown empty this time.

In summary - when you move from a record with a populated ''key'' to a
record with a null ''key'' field - incorrect values will *always* be
displayed. When you move from record with a null ''key'' field to another
record with a null ''key'' field - correctly a *blank* will *always* be
displayed in the comboBox. Records with a populated ''key'' filed will
*always display correct values.

What is the reason for the wrong display behavior?
What is the solution to get proper display behavior?

========================
BTW - Here is the order in which I populate and bind the controls and
datagrid.
1.) populate the dataset with the datatables for the datagrid, controls
and the combobox
2.) set the combobox datasource, value and display members
3.) set the datagrid datasource and datamember
4.) bind the controls to the datatable and corresponding field
5.) set the binding context to the datatable




不确定你在5号的意思。


尽管其他人似乎有类似的空值值问题

和查找组合,我无法重现这个问题。在第一个null上它甚至可以完美地工作。


也许你可以发布重现这个问题的整个代码?

什么您使用的是框架版本吗?


hth,

问候



Not sure what you mean in number 5.

Altough it seems that other people had a similar problem with null values
and lookup combo, i can not reproduce this problem. It works perfectly even
on the first null.

Maybe you could post the entire code that reproduces this problem ?
What version of framework are you using ?

hth,
greetings




" dbuchanan" <分贝********* @ hotmail.com>在消息中写道

news:11 ********************** @ g49g2000cwa.googlegr oups.com ...
Hi,

"dbuchanan" <db*********@hotmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
ComboBox数据绑定问题

==如何设置和使用ComboBox:

我的comboBox由查找表填充。 ValueMember是
查找表的Id,DisplayMember是查找表中
对应字段的文本。在我的数据表中,我们将
ID存储在我称之为键的字段中。

==所需操作的描述:

1 。)当用户选择数据网格中的记录时,绑定的组合框
显示存储在
数据表的''键'字段中的相应值的DisplayMember。
2。当用户选择'key字段为空(没有选择或保存)的记录时,comboBox显示应该为空以表示该事实。

==问题描述:

简单地说,上面的#2没有发生。这是做什么的;当用户移动到数据网格中'key字段为空的记录时,
组合框不是*为空,它会错误地显示第一个可能的选项。 comboBox。

==其他事实:(仔细阅读 - 这可能有点令人困惑)

考虑第一条记录存储值的情况''key''
字段以及''key''字段为空的第2和第3条记录。
这是当我们浏览记录时会发生的事情;
In第一条记录:组合框始终显示与键字段对应的正确值。
当用户移动到第二条记录时:错误 - 显示值而不是当用户移动到第3条记录时:正确 - 组合框显示为空。
当用户移回第2条记录时:正确 - 组合框是
这次显示为空。

总之 - 当你移动时e从带有填充''键''的记录到带有空''key''字段的
记录 - 将显示不正确的值*总是*显示。当您从具有空键字段的记录移动到具有空键字段的另一个
记录时 - 正确地*空白*将*总是*将显示在组合框中。带有填充的钥匙记录的记录将始终显示正确的值。

错误的显示行为是什么原因?
什么是正确的解决方案显示行为?

========================
BTW - 这是我填写的顺序和绑定控件和
datagrid。
1.)使用数据表格填充数据集,控件
和组合框
2.)设置组合框数据源,值和显示成员
3.)设置datagrid数据源和数据库
4.)将控件绑定到数据表和相应的字段
5.)将绑定上​​下文设置为数据表
ComboBox databindng Problem

== How the ComboBox is setup and used:

My comboBox is populated by a lookup table. The ValueMember is the
lookup table''s Id and the DisplayMember is the text from a
corresponding field in the lookup table. In my data table we store the
ID in what I will call the ''key'' field.

== Description of the desired operation:

1.) When the user selects a record in the datagrid the bound comboBox
displays the DisplayMember of the corresponding Value stored in the
data table''s ''key'' field.
2.) When the user selects a record in where the ''key'' field is null (no
selection was made or saved) the comboBox display should be empty to
indicated that fact.

== Description of the problem:

Simply put, #2 above does not happen. Here is what does; When the user
moves to a record in the datagrid in which the ''key'' field is null the
comboBox is *not* empty, it incorrectly displays the first possible
selection in the comboBox.

== Additional facts: (read carefully - this could be a little
confusing)

Consider a scenario in which the 1st record stores a value in the ''key''
field and in the 2nd and 3rd records in which the ''key'' field is null.
Here is what happens when we walk through the records;
In the 1st record: the comboBox always displays the correct value
corresponding to the ''key'' field.
As the user moves to the 2nd record: incorrectly - values are shown
rather than being empty.
As the user moves to the 3rd record: correctly - the comboBox is shown
empty.
As the user moves back to the 2nd record: correctly - the comboBox is
shown empty this time.

In summary - when you move from a record with a populated ''key'' to a
record with a null ''key'' field - incorrect values will *always* be
displayed. When you move from record with a null ''key'' field to another
record with a null ''key'' field - correctly a *blank* will *always* be
displayed in the comboBox. Records with a populated ''key'' filed will
*always display correct values.

What is the reason for the wrong display behavior?
What is the solution to get proper display behavior?

========================
BTW - Here is the order in which I populate and bind the controls and
datagrid.
1.) populate the dataset with the datatables for the datagrid, controls
and the combobox
2.) set the combobox datasource, value and display members
3.) set the datagrid datasource and datamember
4.) bind the controls to the datatable and corresponding field
5.) set the binding context to the datatable




不确定你在5号的意思。


尽管其他人似乎有类似的空值值问题

和查找组合,我无法重现这个问题。在第一个null上它甚至可以完美地工作。


也许你可以发布重现这个问题的整个代码?

什么您使用的是框架版本吗?


hth,

问候



Not sure what you mean in number 5.

Altough it seems that other people had a similar problem with null values
and lookup combo, i can not reproduce this problem. It works perfectly even
on the first null.

Maybe you could post the entire code that reproduces this problem ?
What version of framework are you using ?

hth,
greetings


>不确定你在5号的意思。


这就是5号的意思...

这个变量已经创建了;


受保护WithEvents _bmb为BindingManagerBase


然后就在控件绑定之后我这样做了;

_bmb = Me.BindingContext(_dt)
> Not sure what you mean in number 5.

Here is what I mean by number 5...
This variable is created;

Protected WithEvents _bmb As BindingManagerBase

Then just after the controls binding I do this;
_bmb = Me.BindingContext(_dt)
您使用的是哪个版本的框架?
DotNet framework 1.1.4322 SP1

Visual Studio 2003版本7.1.3088

也许你可以发布重现这个问题的整个代码?
What version of framework are you using ? DotNet framework 1.1.4322 SP1
Visual Studio 2003 Version 7.1.3088
Maybe you could post the entire code that reproduces this problem ?



我会在一天内尝试这样做。


I''ll try to do this within a day.


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

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