加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

DataGridView自动显示行号(VB.NET)

发布时间:2020-12-16 22:37:05 所属栏目:大数据 来源:网络整理
导读:如果想在DataGridView控件中自动添加行号,您可以在DataGridView控件CellPainting事件中添加相关代码。以下就是相关代码: Private Sub DataGridView1_CellPainting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventA

如果想在DataGridView控件中自动添加行号,您可以在DataGridView控件CellPainting事件中添加相关代码。以下就是相关代码:

Private Sub DataGridView1_CellPainting(ByVal sender As Object,ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting

'判断条件是:满足行数索引号要大于或等于0 and 列数的索引号时小于0
If e.ColumnIndex < 0 And e.RowIndex >= 0 Then
e.Paint(e.ClipBounds,DataGridViewPaintParts.All)
Dim indexrect As Drawing.Rectangle = e.CellBounds
'定义显示的行号的坐标
indexrect.Inflate(-2,-2)
'绘画字符串的值
TextRenderer.DrawText(e.Graphics,(e.RowIndex + 1).ToString(),e.CellStyle.Font,indexrect,e.CellStyle.ForeColor,TextFormatFlags.Right)
e.Handled = True
End If

End Sub

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读