我只需要将活动的主要主题以粗体显示(突出显示),DataGridView就会自动填充一个按钮。
Dim Table As New DataTable
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Table.Columns.Add("Operation", Type.GetType("System.String"))
DataGridView1.DataSource = Table
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'----------------ENGINEERING
Table.Rows.Add("ENGINEERING")
End Sub
我该如何解决?谢谢!
答案 0 :(得分:0)
这可能会帮助您指出正确的方向。如果GetFont为'True',它将单元格的字体设置为粗体。
Private Sub DataGridView1_RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles DataGridView1.RowsAdded
'--- Make sure we have a row with data in it
if DataGridView1.rows(e.rowindex) is nothing then exit sub
if DataGridView1.Columns(0).Name = "" Then Exit Sub
'--- Set the font
SetFont(DataGridView1.rows(e.rowindex))
End Sub
Private Sub SetFont(pRow as DataGridViewRow)
Try
'--- Check if the value is a header
If pRow.Cells("fecha inicial").Value IsNot Nothing Then
'--- The value is a header so get the bold font
pRow.Cells("opericion").Style.Font = GetFont(True)
Else
'--- The value is not a header so get the default font
pRow.Cells("opericion").Style.Font = GetFont(False)
End If
Catch ex As Exception
MsgBox("Error ", MsgBoxStyle.OkOnly, "Error")
End Try
End Sub
Private Function GetFont(p As boolean) As Font
'--- Set the default font
Dim f As Font = New Font("Verdana", 14)
If p = True Then
'--- Set the font that with the bold
f = New Font("Verdana", 14, FontStyle.Bold)
End If
Return f
End Function