![]() ![]() ![]() Thank You Reed.This is even more easier and better. Reed Kimble - "When you do things right, people won't be sure you've done anything at all" ![]() If e.ColumnIndex = -1 AndAlso e.RowIndex > -1 AndAlso e.RowIndex < - 1 Thenĭim indexString As String = (e.RowIndex + 1).ToStringĭim sz As SizeF = e.Graphics.MeasureString(indexString, DataGridView1.Font)ĭim pt As New PointF(e.CellBounds.Width - sz.Width, e.CellBounds.Y + (e.CellBounds.Height / 2 - sz.Height / 2))Į.Paint(e.ClipBounds, DataGridViewPaintParts.All)Į.Graphics.DrawString(indexString, DataGridView1.Font, Brushes.Black, pt) Private Sub DataGridView1RowsAdded(sender As Object, e As DataGridViewRowsAddedEventArgs) Handles DataGridView1. Private Sub DataGridView1_CellPainting(sender As Object, e As DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting In your code behind page if you want to get the index number of the row, you can use code similar to this:Int32 idNumber Convert.ToInt32 (gvlisting.Rows i.DataItemIndex.ToString ()) + 1 This assumes you were using an iterator 'i' to get other values from your rows, and you need to add one to the number since the index is ordinal (index 0. DataGridViewRowsAddedEventArgshas two properties, RowIndex (the index of the first added row) and RowCount (the number of rows You should probably be using RowCount to loop through all the added rows. ![]() Still result in sequential row numbering (it is not clear if that is the desired behavior). This assumes that changing row order (via a sort for example) should Assuming an unbound datagrid where the row header number is for display purposes only, you can draw it dynamically and not worry about associating the number with a particular row. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |