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; } } } }