日期:2014-05-18  浏览次数:20802 次

《《datagridview控件合并单元格问题》》求指导啊~~~~ 急啊,毕业设计



datagridview cellpainting事件代码:
if (e.RowIndex != -1)
  {
  using
  (
  Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
  backColorBrush = new SolidBrush(e.CellStyle.BackColor)
  )
  {
  using (Pen gridLinePen = new Pen(gridBrush))
  {
  // 清除单元格
  e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

  // 画 Grid 边线(仅画单元格的底边线和右边线)
  // 如果下一行和当前行的数据不同,则在当前的单元格画一条底边线
  if (e.RowIndex < dataGridView1.Rows.Count - 1 &&
  dataGridView1.Rows[e.RowIndex + 1].Cells[e.ColumnIndex].Value.ToString() !=
  e.Value.ToString())
  e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
  e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
  e.CellBounds.Bottom - 1);
  // 画右边线
  e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
  e.CellBounds.Top, e.CellBounds.Right - 1,
  e.CellBounds.Bottom);

  // 画(填写)单元格内容,相同的内容的单元格只填写第一个
  if (e.Value != null)
  {
  if (e.RowIndex > 0 &&
  dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() ==
  e.Value.ToString())
  { }
  else
  {
  e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
  Brushes.Black, e.CellBounds.X + 2,
  e.CellBounds.Y + 5, StringFormat.GenericDefault);
  }
  }
  e.Handled = true;
  }
  }
  }


效果图如上~~  
  不是我想要的,这种方法是对所有相同单元格进行合并,很不规范,我想实现同代码下,相同单元格才合并,比如1013,1027,它们记分都为0,但是不能合并它们  
  不知道我说的清楚不, 麻烦指点下~怎么实现?


------解决方案--------------------
http://download.csdn.net/detail/ireenter/4086911
这个就可以实现了。你可以参考看看