'请空单元格
g.FillRectangle(New SolidBrush(BackColor), bounds)
' 绘制值
Dim s As String = Me.GetColumnValueAtRow([source], rowNum).ToString() 'parent[rowNum, 0].ToString() + ((parent[rowNum, 1].ToString())+ " ").Substring(0,2);
g.DrawString(s, parent.Font, New SolidBrush(ForeColor), bounds.X, bounds.Y)
Dim bm As Bitmap
If m_Row = rowNum Then bm = Me.m_FacePressed Else bm = Me.m_Face
g.DrawImage(bm, bounds.Right - bm.Width, bounds.Y)
End Sub
End Class
调用代码:
Private Function getdatagridstyle(ByVal table As DataTable) As DataGridTableStyle
Dim style As New DataGridTableStyle()
style.MappingName = table.TableName
style.RowHeaderWidth = 15
Dim i As Integer
For i = 0 To table.Columns.Count - 1
If i = 1 Then
Dim textButtonColStyle As New mybuttondatagridtablestyle1(i) 'pass the column#
textButtonColStyle.HeaderText = table.Columns(i).ColumnName
textButtonColStyle.MappingName = table.Columns(i).ColumnName
'hookup our cellbutton handler...
AddHandler textButtonColStyle.CellButtonClicked, AddressOf HandleCellButtonClick
style.GridColumnStyles.Add(textButtonColStyle)
'hook the mouse handlers
AddHandler DataGrid1.MouseDown, AddressOf textButtonColStyle.HandleMouseDown
AddHandler DataGrid1.MouseUp, AddressOf textButtonColStyle.HandleMouseUp
Else
Dim c As New DataGridTextBoxColumn()
c.HeaderText = table.Columns(i).ColumnName
c.MappingName = table.Columns(i).ColumnName
style.GridColumnStyles.Add(c)
End If
Next
Return style
End Function
Private Sub HandleCellButtonClick(ByVal sender As Object, ByVal e As DataGridCellButtonClickEventArgs)
MessageBox.Show(("row " + e.RowIndex.ToString() + " col " + e.ColIndex.ToString() + " clicked."))
End Sub