为什么组合框刷新不起作用?

发布于 2024-08-24 02:33:07 字数 896 浏览 2 评论 0原文

我有一个复杂的问题,你能帮我吗?

问题:

我有一个带有 TabControl 的表单。有两个 TabPages,第一个是 dataGridView,第二个是多个 comboboxes

DataGridView 填充了 Table1 中的数据,在另一个选项卡上,第一个 combobox 数据源设置为 TableCB1,第二个 comboboxTableCB2 等等。

TableCB1、TableCB2 之间 ... 是 DataRelations 就像 (TableCB1. ID->TableCB2.ParentID)。我正在使用数据绑定将当前列从表绑定到控件。

当我打开表单时,第一个 tabPage (dataGridView) 已填充并且工作正常,但如果我选择第二个 TabPage(带有 comboboxes),则 组合框所选项目未正确选择!!! 只有第一个组合框设置正确,但所有其他组合框都选择了数据源中的第一个项目,直到我更改绑定源位置或进行更改dataset.rejectchanges()

但是,如果使 TabPage 在表单加载时显示两个,则组合框项目将被正确选择!

我知道这是一个非常具体的问题,但是希望有人可以帮助我解决这个问题。

我在.NET3.5和winforms上做。

谢谢。

I have a complex problem, could you please help me.

The problem:

I have a form with a TabControl. There are two TabPages in the first is a dataGridView and in the second are multiple comboboxes.

DataGridView is filled with data from Table1, on the other tab the first combobox datasource is set to TableCB1, the second combobox to TableCB2 etc.

Between TableCB1, TableCB2 ... are DataRelations like (TableCB1.ID->TableCB2.ParentID). I'm using databindings to bind current columns from table to controls.

When I open the form, first tabPage (dataGridView) is filled and works ok, but if I select the second TabPage (with comboboxes) then the combobox selected items are not correct selected!!! Only the first combobox is set correctly but all other have selected the first item in datasource until I change the bindingsource position or make dataset.rejectchanges().

But if make TabPage two to be shown on form load, then the combobox items are selected correctly!

I know it's a very specific problem but, hope somebody could help me to solve this problem.

I'm doing it on .NET3.5 and winforms.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗳卜坏 2024-08-31 02:33:07

线程中的回复可能是您所需要的:

在创建控件之前,控件上不会发生数据绑定。 TabPage 仅在 TabPage 可见后才创建子控件。要发生数据绑定,您需要强制创建 TabPage 上的子控件,实现此目的的一种方法是显示/隐藏 TabPage(正如您所发现的)。

The reply in this thread might be what you need:

DataBinding doesn't occur on Controls until the Controls are created. A TabPage creates child controls only after the TabPage has been made visible. To get DataBinding to occur, you'll need to force the child controls on the TabPage to be created and one way you can do that is by showing/hiding the TabPage (as you have discovered).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文