TabControl中有个tp的页,tp中有个叫dg的DataGrid控件,怎么把它取出来?

解决方案 »

  1.   

    for(int intNum=0;intNum<=TabContol.TabPages.count-1;intNum++)
    {
    tabpage tap=TabContol.TabPages[intNum];
    foreach control dd in tap.control
    {
    if(dd is DataGrid)
    {
    //处理
    }}}
      

  2.   

    重写TabControl, 添加bool的property, 判断是否有dg这项或tp这项
      

  3.   

    this.tabPage1.Controls,所有的控件都在controls里,如果只有一个DataGridView控件,那就是this.tabPage1.Controls[0],如果又其他的控件,就迭代controls。找到你要的
      

  4.   

    又或者        private bool _hasTabPage;
            private bool _hasDataGridView;        void tabControl_ControlAdded(object sender, ControlEventArgs e)
            {
                if (e.Control is TabPage) _hasTabPage = true;
            }        void tabPage_ControlAdded(object sender, ControlEventArgs e)
            {
                if (e.Control is DataGridView) _hasDataGridView = true;
            }        public bool HasTabPage
            {
                get { return _hasTabPage; }
                set { _hasTabPage = value; }
            }        public bool HasDataGridView
            {
                get { return _hasDataGridView; }
                set { _hasDataGridView = value; }
            }