单击搜索表单的 datagridview 的一行后如何提供 winform?
我有一个 winform ,它负责根据用户输入的某些条件进行搜索,然后从数据库中选择记录。 搜索表单有一个显示结果的数据网格视图。 搜索后,用户单击datagridview的一行,然后将显示另一个表单(例如frmShowDetails)。
我的问题是,当显示 frmShowDetails 时,您有什么建议将所选行的 id 发送到 frmShowDetails 以便将其提供给在 .net 中显示数据?您是否使用表单属性或仅由表单构造函数设置的私有变量?
I have a winform which is responsible for doing a search by some conditions that users enters and then selects the records from a Database.
The search form has a data grid view which shows the result.
After searching, user clikcs on a row of the datagridview and then another form (for example frmShowDetails) will be displayed.
My question is when displaying frmShowDetails, what are your suggestions to send the id of selected row to frmShowDetails in order to feed it to show data in .net? Do you use form property or a private variable which sets by only form constructor?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通过将 DataRow 的 id 作为参数发送,您将不得不再次调用 DB 来获取详细信息。相反,创建一个类型来保存将在 ShowDetailsForm 中显示的数据。在显示表单之前,用数据填充类型并将其传递给 ShowDetailsForm ctor。
By sending the id of the DataRow as a parameter you will have to make another call to DB to get the details. Instead create a Type that holds the data which would be displayed in the ShowDetailsForm. And before showing the Form populate the Type with data and pass it on to the ShowDetailsForm ctor.
将构造函数中的参数传递给 frmShowDetails。
Pass parameter in a constructor to frmShowDetails.
我通常使用表单属性。有一种感觉,通过 ctor 传递数据不是一个很好的决定,但我可能是错的。
I usually use form properties. Have a feeling, that passing data through ctor is not a very good decision, but I might be wrong.