我在form中加入了一个tabcontrol,里面有两个标签,每个标签上各放了一个datagridview.现在我想把每个标签上的datagridview的前两行冻结。我在form1_load事件中是这样写的: 
dataGridView1.Rows[1].Frozen=true; 
dataGridView2.Rows[1].Frozen=true; 
可是运行后结果是,dataGridView1的前两行冻结了,而dataGridView2没有冻结。这是怎么回事? 我又试了一下把两个datagridview中的第一个单元格背景变颜色: 
dataGridView1.Rows[0].cell[0].style.backcolor=color.red; 
dataGridView2.Rows[0].cell[0].style.backcolor=color.red; 
结果也是datagridview1变了,而datagridview2没变。 我不明白为什么第二个标签上的设置会不起作用呢? 

解决方案 »

  1.   

    你如果确定说每个Tab只有一个控件的话
    DataGridView cb =(DataGridView )this.tabPage1.Controls[0];
    cb.Rows[0].cell[0].style.backcolor=color.red; 
    然后
    DataGridView cb =(DataGridView )this.tabPage2.Controls[0];
    cb.Rows[0].cell[0].style.backcolor=color.red; 
      

  2.   

    每个tab是就一个控件,不过还是不行啊
      

  3.   

    我觉得这个设置datagridview的属性和它再那个控件上没有关系,是不是你其它方面出了问题!
      

  4.   


    缺省情况下,form 显示的时候只有第一个tabpage会 load。
    其它 tabpage只有选择的时候才会load。
    如果想要设定样式,可以先加上 tabpage.show()就可以了。
      

  5.   

    As default, the tabpages except the first page does not load when the form is shown. A tabpage would load when we select it and it is shown. The row styles of the DataGridView can only be modified and make sense when all the UI elements of the DataGridView load, so just add tabPage.show() before your sentence.