DataGridView展开与收缩功能实现

2019-05-23 00:38:45丽君

收缩的时候,我们直接隐藏行就可以了.

收缩行

if (this.dataGridView1.Columns[e.ColumnIndex].Name == "EX" && isEx == "true") 
      { 
        int RowCount = Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells["RowCount"].Value); 
        for (int i = 1; i <= RowCount; i++) 
        { 
          //隐藏行 
          this.dataGridView1.Rows[e.RowIndex + i].Visible = false; 
        } 
        ////将IsEx设置为false,标明该节点已经收缩 
        this.dataGridView1.Rows[e.RowIndex].Cells["IsEx"].Value = "false"; 
        this.dataGridView1.Rows[e.RowIndex].Cells["EX"].Value = "+"; 
      } 

大家知道DataGridView是如何实现展开收缩的吧,希望大家不仅知道是如何实现的还要动手实验一番,才不枉小编辛苦整理此文章哦