DataGridView 中 Cell 合併再給予新值

Merge Cell
將 DataGridView 中 Cell 合併再給予新值
請注意
只有繪製效果而已,實際欄位仍然存在
參考資料:http://msdn.microsoft.com/zh-tw/library/system.drawing.rectangle_members(VS.90).aspx

 Dim MyDataTable As New DataTable()
       
With MyDataTable
           
.Columns.Add("Col1")
           
.Columns.Add("Col2")
           
For i As Integer = 0 To 4
               
.Rows.Add(i, Rnd())
           
Next
       
End With
       
With DataGridView1
           
.DataSource = MyDataTable
           
.ReadOnly = True
           
.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
           
.RowHeadersVisible = False
       
End With
   
End Sub
   
Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
                                                                                                     
Handles DataGridView1.CellPainting
       
With DataGridView1
           
Dim Rectangle1 As Rectangle = .GetCellDisplayRectangle(0, 0, True)
           
Dim Rectangle2 As Rectangle = .GetCellDisplayRectangle(0, 1, True)
           
Dim Rectangle3 As Rectangle = .GetCellDisplayRectangle(0, 2, True)
           
Dim Rectangle4 As Rectangle = .GetCellDisplayRectangle(0, 3, True)
           
Dim Rectangle5 As Rectangle = .GetCellDisplayRectangle(0, 4, True)
           
Rectangle1.X += 1
           
Rectangle1.Width -= 2
           
Rectangle1.Height = Rectangle1.Height + Rectangle2.Height + Rectangle3.Height + Rectangle4.Height + Rectangle5.Height - 1
            e
.Graphics.FillRectangle(Brushes.White, Rectangle1)
            e
.Graphics.DrawString("Merge", .Font, Brushes.Red, Rectangle3)

沒有留言:

張貼留言