选择C#的WinForms TabControl的元件读取为空,直到TabPage的 [英] C# Winforms TabControl elements reading as empty until TabPage selected

查看:207
本文介绍了选择C#的WinForms TabControl的元件读取为空,直到TabPage的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有winform应用程序,我在C#编写。在我的表,我有七页,每个完整的内容(文本框和DropDownLists,主要是)一个TabControl。我拉在与一个DataReader一些信息,填充数据表,并使用元素的DataBindings.Add方法来填充与电流值的那些元素

I have Winform app I am writing in C#. On my form, I have a TabControl with seven pages, each full of elements (TextBoxes and DropDownLists, primarily). I pull some information in with a DataReader, populate a DataTable, and use the elements' DataBindings.Add method to fill those elements with the current values.

用户能够将数据输入到这些因素,按保存,然后我将用元素的文本字段的UPDATE查询的参数。例如:

The user is able to enter data into these elements, press "Save", and I then set the parameters of an UPDATE query using the elements' Text fields. For instance:

updateCommand.Parameters.Add("@CustomerName", SqlDbType.VarChar, 100).Value = CustomerName.Text;



我的问题是,一旦我加载的形式,所有的元素都显然认为是空的,直到我手动选择的每个选项卡。因此,如果我按保存后立即加载的形式,所有的字段上,我还没有尝试选择空数据来更新(不是很好)的的TabPages。当我选择每个TabPage的,这些元素会沿着现在正确地发送它们的数据。从目前来看,我已经摸索出了(非常)丑陋的解决办法,我以编程方式选择每个TabPage的当数据被填充的第一次,但是这是无法接受的长期解决方案。

The problem I have is that once I load the form, all of the elements are apparently considered empty until I select each tab manually. Thus, if I press "Save" immediately upon loading the form, all of the fields on the TabPages that I have not yet selected try to UPDATE with empty data (not nice). As I select each TabPage, those elements will now send their data along properly. For the time being, I've worked out a (very) ugly workaround where I programmatically select each TabPage when the data is populated for the first time, but that's an unacceptable long-term solution.

我的问题是,我怎么能得到所有的的TabPages元素返回其数据的用户选择之前正确的TabPage的?

My question is, how can I get all of the elements on the TabPages to return their data properly before the user selects that TabPage?

推荐答案

浩是正确的;直到选择了TabPage的不创建一个TabPage的元素。我只是说在它选择的每个TabPage的,现在它工作正常形式的负载循环。

ho is correct; the elements on a TabPage are not created until that TabPage is selected. I just added a loop upon form load that selects each TabPage and now it works fine.

foreach (TabPage tp in tabControl1.TabPages)
    {
        page.Show();
    }

这篇关于选择C#的WinForms TabControl的元件读取为空,直到TabPage的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆