向ACCDB数据集中添加记录后,如何在运行时刷新ComboBox的ItemsSource? [英] How do I refresh the ItemsSource for a ComboBox during runtime after adding a record to my ACCDB dataset?

查看:41
本文介绍了向ACCDB数据集中添加记录后,如何在运行时刷新ComboBox的ItemsSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在开发此软件的各个阶段中,我在这里提出了多个问题.

I have posted multiple questions here as I have struggled through the stages of developing this software.

我的应用程序有两个窗口(在Visual Studio 2015中使用WPF和C#).

My application has two windows(using WPF and C# in Visual Studio 2015).

第一个窗口显示:

(1)一个按钮,允许用户在详细信息表单记录中搜索任何所需字段内的任何子字符串(通过在所选字段中输入部分字符串进行搜索,然后指向并单击按钮以执行搜索) ).  然后是一个新窗口 显示,列出在选定字段中找到部分值的每个记录的主键数据值.然后,用户可以从列表中点击所需的主键值,以打开其记录并显示其所有值,从而 进行编辑(如果需要).  进行修改后,用户指向并单击一个保存按钮.)

(1)a button which allows the user to search the detail form records for any substring within any desired field(by entering a partial string into the chosen field to search, then pointing-and-clicking a button to execute the search).  A new window then displays, listing the primary key data value for each record for which the partial value is found in the chosen field.  The user can then point-and-click on the desired primary key value from the list to open its record and show all of its values, making edits, if desired.  After making edits, the user points-and-clicks a save button.).

(2)一个组合框,用于显示数据集中的主键值,并带有一个按钮,用于打开新窗口并在用户从列表中选择主键值后显示记录.

(2)a ComboBox which displays the primary key values within the dataset, accompanied by a button to open a new window and display a record after the user selects a primary key value from the list.

(3)一个按钮,用于打开详细信息表单,所有字段均为空白,以便分配新记录.  添加数据值后,用户然后指向并单击一个保存按钮.

(3)a button to open the detail form with all fields blank, in order to allocate a new record.  After data values are added, the user then points-and-clicks a save button.

唯一剩下的问题是:

ComboBox显示了在打开程序时存在的所有主键值,但是我需要刷新ComboBox的ItemsSource,以便在添加每个新记录后将主键值添加到ComboBox中,就像上面的(3)一样.

The ComboBox shows all primary key values in existence at the time the program is opened, but I need to refresh the ItemsSource for the ComboBox, so that a primary key value will be added to the ComboBox after each new record is added, as in (3) above.

我确实知道该应用程序可以使用新添加的记录.  它们会适当地显示在搜索结果(1)中.

I do know that the newly-added records are available to the app.  They appear in the search results (1), as appropriate.

组合框是唯一未更新以使其可用的位置.

The Combobox is the only place that does not update to make them available.

任何帮助将不胜感激.  我现在的项目确实可以运行,但是最后的功能还没有.

Any help would be much appreciated.  My project as it is now does run, but that last capability is not yet there.

非常感谢您!

推荐答案

ComboBox的ItemsSource应该是一个集合,用于通知GUI有新条目.

The ItemsSource for the ComboBox should be a collection that notifies the GUI that there is a new entry.

执行此操作的最佳方法是使用ObservableCollection.  数据集不具备此功能.

The best way to do this is to use a ObservableCollection.  A DataSet does not have this capability.


这篇关于向ACCDB数据集中添加记录后,如何在运行时刷新ComboBox的ItemsSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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