C# 将 formname.designer.cs 中生成的 dataTable 设置为静态
我想知道是否可以修改 formname.designer.cs 并将从设计模式生成的变量设置为私有静态:
private dtableAdapters.llist nameTable;// this to become static
public static dtableAdapters.llist nameTable;//like this
我在这里阅读 C# Set Checkbox to Static 这不是一个好方法。 也许我可以用其他方式做到这一点。这就是我想要做的:
我有一个包含更多表单的表单,在面板中打开。一种表单包含一些带有数据库值的组合框。问题是,当我从带有文本框的另一个表单向数据库添加更多值时,需要再次填充组合框。我认为如果我在添加一些值后立即更新组合框,这可能会很容易。 (组合框和文本框 - 在数据库中添加由组合框显示的值 - 具有不同的形式)。
您还有其他这样做的想法吗?我还尝试在单击组合框时再次填充组合框,但因为我有更多组合框,所以当我快速从一个组合框单击到另一个组合框时,我会遇到一些致命错误。
编辑:作为最后一种方法:我可以添加一个按钮并在按下按钮时填充组合框,但我想自动执行此操作
(winforms而不是Web表单)
I want to know if it's ok to modify the formname.designer.cs and to set a variable that is generated from design mode as private as static:
private dtableAdapters.llist nameTable;// this to become static
public static dtableAdapters.llist nameTable;//like this
I read here C# Set Checkbox to Static that is not a good method.
Maybe I can do this in other way. Here is what I want to do:
I have a Form that contain more forms, opened in a panel. One form contains some comboboxes with values from the database. The problem is that when I add more values to the database from another form with a textbox, the combobox needs to be filled again. I thought that it could be easy if I update the combobox immediatlly after i add some values.
(combobox and the textbox -that add values in the database which are shown by combobox- are in different forms).
Do you have an other ideea of doing this? I have tried also to fill the combobox again when it's clicked but because I have more comboboxes I get some fatal errors when I click fast from one to another.
edit: as a last method: I could add a button and fill the combobox when the button is pressed, but I want to do it automatically
(winforms not web forms)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是在添加值时在 FormA 上触发事件。
Form B 可以订阅事件并更新列表。
唯一棘手的一点是 FormB 需要引用 FormA 才能连接到事件。
像这样的东西...
FormA
FormB
One approach is to fire an event on FormA when a value is added.
Form B can subscribe to the event and update the list.
The only tricky bit is that FormB needs a reference to FormA to hook up to the event.
Something like this...
FormA
FormB