DataGridView合并单元格(一列或一行)

#region"合并单元格的测试(一列或一行)"

// int?是搜索一种类型(可空类型),普通的int不能为null,而用int?,其值可以为null

//private int? nextrow = null;

//private int? nextcol = null;

 

//在CellPainting方法后调用

private void dataGridView1_CellFormatting(object sender, System.Windows.Forms.DataGridViewCellFormattingEventArgs e)

{

    /*

    //列标示

    if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "PARENTID"  && e.RowIndex >= 0)

    {

        //若与下一行同列单元格值相同则修改设置

        if (e.RowIndex < this.dataGridView1.RowCount - 1 && this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value != null)

        {

            if (e.Value.ToString() == this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString())

            {

                e.CellStyle.BackColor = Color.LightPink;

                this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Style.BackColor = Color.LightPink;

                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;

                //this.dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].ReadOnly = true;

            }

        }

         

    }

    */

 

    /*

    //行标示

    if (e.ColumnIndex >= 0 && this.dataGridView1.Columns[e.ColumnIndex].HeaderText == "PHONE1" && e.RowIndex >= 0)

    {

        //若与同行下一列单元格值相同则修改设置

        if (e.ColumnIndex != this.dataGridView1.ColumnCount - 1 && this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value != null)

        {

            if (e.Value.ToString() == this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Value.ToString())

            {

                e.CellStyle.BackColor = Color.LightBlue;

                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex + 1].Style.BackColor = Color.LightPink;

                this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].ReadOnly = true;

                //this.dataGridView1.Rows

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值