读书人

高分求解:怎么设置datagridview行头与

发布时间: 2011-12-31 23:50:30 作者: rapoo

高分求解:如何设置datagridview行头与列头交叉处单元格的值
如题.....

[解决办法]

VB.NET code
Public Class Form1    Private DataGridView1 As New DataGridView    Private Label1 As New Label    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        AddHandler DataGridView1.CellPainting, AddressOf DataGridView1_CellPainting        Me.DataGridView1.AllowUserToResizeRows = False        Me.DataGridView1.AllowUserToResizeColumns = False        Me.DataGridView1.Dock = DockStyle.Fill        Me.DataGridView1.Columns.Add("Column1", "Column1")        Me.DataGridView1.Columns.Add("Column2", "Column2")        Me.Label1.Visible = False        Me.Label1.Text = "test"        Me.Label1.AutoSize = False        Me.BackColor = Color.BlueViolet        Me.Label1.BorderStyle = BorderStyle.Fixed3D        Me.Label1.TextAlign = ContentAlignment.MiddleCenter        Me.Controls.Add(DataGridView1)        Me.Controls.Add(Label1)    End Sub    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs)        If e.RowIndex = -1 And e.ColumnIndex = -1 Then            Dim p As Point = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, True).Location            p.Offset(Me.DataGridView1.Left, Me.DataGridView1.Top)            Me.Label1.Location = p            Dim s As Size = Me.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, False).Size            Me.Label1.Size = s            Me.Label1.Visible = True            Me.Label1.BringToFront()        End If    End SubEnd Class 

读书人网 >VB Dotnet

热点推荐