Solved

Vb.Net - Adding Rows Numbers to DataGrid

Posted on 2013-11-15
3
2,219 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now