简体   繁体   English

WinForms中的选项卡控件+ DataGridView

[英]Tab control + DataGridView in WinForms

I have multiple results sets coming back from a server request against a datasource. 我有多个结果集从针对数据源的服务器请求返回。 I want to organise these with a WinForms tabPage for each result set, on a single tabControl. 我想在单个tabControl上为每个结果集使用WinForms tabPage来组织这些。 I am displaying the data in a DataGridView, but want to avoid having a DataGridView instance on each tabPage - I'd rather intercept the "switching to new tab page" message, and load up the appropriate results set from my local cache. 我在DataGridView中显示数据,但要避免在每个tabPage上都有一个DataGridView实例-我宁愿截取“切换到新标签页”消息,并从本地缓存中加载适当的结果集。 Is there an easy/obvious way to do this? 有没有简单/明显的方法可以做到这一点?

Create a tab control as usual and then put a DataGridView on top of it (be sure not to put it inside a tab page). 像往常一样创建一个选项卡控件,然后将DataGridView放在其顶部(请确保不要将其放在选项卡页内)。

Subscribe to the SelectedIndexChanged event and reload the data when the event fires. 订阅SelectedIndexChanged事件,并在事件触发时重新加载数据。

Why would you want to do this? 你为什么想做这个? You'd lose the designability per result set (unless they're all the same structure) and have to manage all of this yourself. 您将失去每个结果集的可设计性(除非它们都是相同的结构),而您必须自己管理所有这些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM