从另一个表单执行表单中的代码

编程入门 行业动态 更新时间:2024-10-10 21:24:17
本文介绍了从另一个表单执行表单中的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个表单form1,它在数据网格视图中显示SQL表中的一些数据。在form1上的菜单工具条中,用户可以发出启动form2的命令。从form2,用户在数据网格视图中的列上输入搜索条件。我希望form2能够执行与form1相同的代码来显示数据网格视图。我该如何做到这一点? 我的尝试: 我还没有尝试过任何东西。

解决方案

最好的方法可能听起来很复杂,但事实并非如此。 创建一个从DataGridView派生的新控件(将UserControl添加到项目中,然后将其从DataGridView派生的内容更改)并添加代码。 然后在Form1和Form2中使用新控件。

表格的数量并不重要!您需要做的就是使用自定义逻辑从Form2获取所有过滤器。如果用户单击[Accept]按钮,则Form1将显示过滤后的数据。 请参阅: 创建Windows表单以搜索数据 [ ^ ] 在表单之间传递数据 [ ^ ]

I have a form, form1, that displays a some data from a SQL table in a data grid view. In a menu tool strip on form1 the user can issue a command that starts form2. From form2 the user enter search criteria on a column in the data grid view. I would like form2 to to execute the same code as form1 to display the data grid view. How do I accomplish this? What I have tried: I have not tried anything yet.

解决方案

The best way may sound complicated, but it isn't, not really. Create a new control derived from DataGridView (add a UserControl to your project, then change what it derives from to DataGridView) and add the code to that. Then use the new control in both Form1 and Form2.

The number of forms is not important! All what you need to do is to use custom logic to get all filters from Form2. If user click [Accept] button then Form1 will display filtered data. See: Create a Windows Form to search data[^] Pass data between forms[^]

更多推荐

从另一个表单执行表单中的代码

本文发布于:2023-11-02 09:59:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1552078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!