DataGridView横向单元格合并通过事件CellPainting,已经实现了.
纵向单元格合并没有做好.单元格在合并以后.字符串在合并后的单元格里没有办法让他居中显示. 
请有这方面的经验的给我指点一下.以下是我画字符串的一段代码
 if (e.Value != null)
                            {
                                if (e.RowIndex > 0 && dataGridView1.Rows[e.RowIndex - 1].Cells[e.ColumnIndex].Value.ToString() == e.Value.ToString())
                                {
                                    float tmpx = 0;
                                    float tmpY = 0;
                                    float tmpheight = 0;
                                    float tmpwidth = 0;
                                    tmpheight = e.CellBounds.Height;
                                    tmpwidth = e.CellBounds.Width;
                                    tmpx = e.CellBounds.X;
                                    tmpY = e.CellBounds.Y;
                                    for (int i = e.RowIndex - 1; i > -1; i--)
                                    {
                                        if (e.Value.ToString() != dataGridView1.Rows[i].Cells[e.ColumnIndex].Value.ToString())
                                        {
                                            break;
                                        }
                                        tmpY += dataGridView1.Rows[i].Cells[e.ColumnIndex].Size.Height;
                                        tmpheight += dataGridView1.Rows[i].Cells[e.ColumnIndex].Size.Height;
                                    }
                                    e.Graphics.FillRectangle(backColorBrush, tmpx, tmpY, tmpwidth, tmpheight);
                                    e.Graphics.DrawString((String)e.Value, e.CellStyle.Font, Brushes.Black, tmpx + 2, e.CellBounds.Y + tmpheight/2, StringFormat.GenericDefault);                                }
                                else
                                {
                                    e.Graphics.DrawString((String)e.Value, e.CellStyle.Font, Brushes.Black, e.CellBounds.X + 2, e.CellBounds.Y + 5, StringFormat.GenericDefault);
                                }