vb.net中DataGridView添加行号
怎样使DataGridView的每行的行号显示出来。
[解决办法]
可以在DataGridView数据绑定之前,对数据源进行处理,增加行号.
[解决办法]
用模板列可以做到,c#中是这样用的,VB就不知道能不能用了,这样试下吧
<ASP:TEMPLATECOLUMN HeaderText= "序号 ">
<ITEMTEMPLATE>
<%#((DataGridItem)Container).ItemIndex+1%>
</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>
[解决办法]
做循环对DataGridView的一列进行处理
[解决办法]
在DataGridView的RowPostPaint事件中添加以下代:
Try
Dim rectangle As New Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, Me.dgrd1.RowHeadersWidth - 4, e.RowBounds.Height)
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), Me.dgrd1.RowHeadersDefaultCellStyle.Font, _
rectangle, dgrd1.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.Right)
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly)
End Try