Do you have to show every tab before all textboxes actually populate?

你离开我真会死。 提交于 2019-12-29 02:08:07

问题


I have a vb.net form that uses multiple textboxes across several different tabs. Within one of those tabs, I have a sub set of tabs. My save functionality calls stored procs for each tab and cycles through the values on each page to either do an update or a "add new". I noticed that while testing, some of the pages do not save or update any of the values in the textboxes. After a few days of investigating, I realized that if I edit something, then physically click through the other tabs, it all saves/updates properly. If I don't click through them, they don't all save. Is there a reason for this that I am missing? When you enter a search value, I cycle through the pages and populate them all at the same time so I was assuming it wrote those values BEFORE it physically rendered...I guess I am wrong?


回答1:


From the TabPage documentation Remarks section

Controls contained in a TabPage are not created until the tab page is shown, and any data bindings in these controls are not activated until the tab page is shown.

So the answer to your question is "Yes the tabpage must be shown".

However, the definition of "shown" is subject to interpretation. In reality, all you need to do set the TabPage.Visible property to True and not actually cycle through and display each TabPage.

A recursive scan of the form for TabPage controls will work:

Private Shared Sub TabPagesVisible(parent As Control)
    For Each c As Control In parent.Controls
        If TypeOf c Is TabPage Then c.Visible = True
        TabPagesVisible(c)
    Next
End Sub

Example usage:

Sub SaveFormTabData()
    TabPagesVisible(Me) ' Me refers to the containing form
    ' code to save control data
End Sub


来源:https://stackoverflow.com/questions/50108553/do-you-have-to-show-every-tab-before-all-textboxes-actually-populate

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!