合并相同项的单元格

  private   void  CellJoin( int  col,  int  mark)
    
{
        String celltext;
//要合并的单元格
        String cellMarktext;//第二个单元格参照
        int i = 0;
        
int j = 0;
        
int k = col;

        celltext 
= grid.Items[0].Cells[col].Text;//要合并的单元格
        cellMarktext = grid.Items[0].Cells[mark].Text;//第二个单元格参照
        for (j = 1; j <= grid.Items.Count - 1; j++)
        
{
            
if (mark == 1)
            
{
                
if (grid.Items[j].Cells[col].Text == celltext)
                
{
                    grid.Items[j].Cells[col].Visible 
= false;//.RemoveAt(k);//隐藏单元格
                    grid.Items[i].Cells[col].RowSpan = j - i + 1;
                }

                
else
                
{
                    celltext 
= grid.Items[j].Cells[col].Text;
                    i 
= j;
                }

            }

            
else
            
{
                
if (grid.Items[j].Cells[col].Text == celltext && grid.Items[j].Cells[mark].Text == cellMarktext)
                
{
                    grid.Items[j].Cells[col].Visible 
= false;//.RemoveAt(k);//隐藏单元格
                    grid.Items[i].Cells[col].RowSpan = j - i + 1;
                }

                
else
                
{
                    celltext 
= grid.Items[j].Cells[col].Text;
                    cellMarktext 
= grid.Items[j].Cells[mark].Text;//第二个单元格参照
                    i = j;
                }

            }

        }

    }





private   void  CellJoin( int  col, int  mark, int  flag)
    
{
        String celltext;
//要合并的单元格
        String cellMarktext;//第一个单元格参照
        String cellflagtext;//第二个单元格参照
        int i = 0;
        
int j = 0;
        
int k = col;

        celltext 
= grid.Items[0].Cells[col].Text;//要合并的单元格
        cellMarktext = grid.Items[0].Cells[mark].Text;//第一个单元格参照
        cellflagtext = grid.Items[0].Cells[flag].Text;//第二个单元格参照
        for (j = 1; j <= grid.Items.Count - 1; j++)
        
{
            
if (mark == 1 && flag==1)
            
{
                
if (grid.Items[j].Cells[col].Text == celltext)
                
{
                    grid.Items[j].Cells[col].Visible 
= false;//.RemoveAt(k);//隐藏单元格
                    grid.Items[i].Cells[col].RowSpan = j - i + 1;
                }

                
else
                
{
                    celltext 
= grid.Items[j].Cells[col].Text;
                    i 
= j;
                }

            }

            
else
            
{
                
if (grid.Items[j].Cells[col].Text == celltext && grid.Items[j].Cells[mark].Text == cellMarktext && grid.Items[j].Cells[flag].Text == cellflagtext)
                
{
                    grid.Items[j].Cells[col].Visible 
= false;//.RemoveAt(k);//隐藏单元格
                    grid.Items[i].Cells[col].RowSpan = j - i + 1;
                }

                
else
                
{
                    celltext 
= grid.Items[j].Cells[col].Text;
                    cellMarktext 
= grid.Items[j].Cells[mark].Text;//第一个单元格参照
                    cellflagtext = grid.Items[j].Cells[flag].Text;//第二个单元格参照
                    i = j;
                }

            }

        }

    }
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值