Solved

Vb.Net - Adding Rows Numbers to DataGrid

Posted on 2013-11-15
3
2,433 Views
Last Modified: 2013-11-18
Good Day Experts!

I am interested in adding row number to my Vb.Net DataGrid.  I don't want to add a column in the data.  I would like to have it in the left-hand column where the row "Indicator" is.

Is this possible? Do you have a reference that can help me achieve this?

Thanks,
jimbo9999
0
Comment
Question by:Jimbo99999
3 Comments
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 400 total points
ID: 39652707
You can do this with the HeaderCell property of the DataGridView :
The following code does it on a button click but you could do this on page_load as well:

' Set row labels. 
Private Sub Button6_Click(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles Button6.Click

    Dim rowNumber As Integer = 1
    For Each row As DataGridViewRow In dataGridView.Rows
        If row.IsNewRow Then Continue For
        row.HeaderCell.Value = "Row " & rowNumber
        rowNumber = rowNumber + 1
    Next
    dataGridView.AutoResizeRowHeadersWidth( _
        DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
End Sub

Open in new window


MSDN DataGridViewRow.HeaderCell Property
0
 
LVL 11

Assisted Solution

by:SAMIR BHOGAYTA
SAMIR BHOGAYTA earned 100 total points
ID: 39655771
hi..

If you want to add row numbers to each row header cell, try this:

New,Courier,Monospace">New,Courier,Monospace">Public Sub AddDgvRowHeaderCell(ByVal DGV As DataGridView)
New,Courier,Monospace">New,Courier,Monospace">'adds numbers for each row header cell
Dim row As DataGridViewRow
Dim i As Integer = 0
For Each row In DGV.Rows
DGV.Rows(i).HeaderCell.Value = (1 + i).ToString
i += 1
Next
End Sub
0
 

Author Closing Comment

by:Jimbo99999
ID: 39656328
Thanks all for replying...it is working now!

jimbo99999
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual Studio .Net 2012 and Crystal Reports 9 68
Help with Query not working in client's PC 1 36
Exit the loop 4 42
location of a form 2 14
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question