I am developing Windows Application in Vb.Net. Now there is one form in which I want to print records displayed in the grid. There is a facility to sort grid by clicking on the cell header in the grid And that should be print as displayed in the grid.
So I am little bit confuse about how to maintain the row number in the grid. I can take row number from DB initially when grid fill and assign data source. But when user clicks any cell header and sort that column then the row number is changed. At that time it is very difficult for me to maintain the row number.
Can any one give me idea how to maintain row number in the grid?
Thanks in advance.
I guess you need this:
NOTE: This code is in C# so you can just convert it to VB.Net
delegate:
this.dgvUserDetails.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dgvUserDetails_RowPostPaint);
Event:
private void dgvUserDetails_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(dgvUserDetails.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
}
}
OUTPUT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With