Solved

VB.Net - Adding Rows To DataGrid

Posted on 2013-12-18
8
362 Views
Last Modified: 2013-12-24
Good Day Experts!

Not too long ago I had a question posted about adding line numbers to the left-most "gray" column in a DataGrid.  I was able to it working for the DataGrid.  Now, I have copied the DataGrid onto 4 tabs on a TabControl and the line numbers don't work!!!

I have tried and tred to look at the code to make sure I am not missing anything. Her is the code I am using for each DataGrid:

Dim row2 As DataGridViewRow
Dim j As Integer = 0
       For Each row2 In dgrdAcceptedSF.Rows
                dgrdAcceptedSF.Rows(j).HeaderCell.Value = (1 + j).ToString
                 j += 1
       Next

Is there anything that may have been reset in the DataGrid when I copied it that may have been reset causing issues you think?

Thanks,
jimbo99999
0
Comment
Question by:Jimbo99999
  • 5
  • 3
8 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39728640
Can you post the complete code in which you set the line numbers for all the DataGrids?

Thanks.
0
 

Author Comment

by:Jimbo99999
ID: 39729030
Dim row As DataGridViewRow
The first block of code for dgrdServiceFailures works! I copied that dataGrid for the 4 other tabs and renamed accordingly.  Then I adjusted the code for each dataGrid...unfortunately those tabs are not working!!!

Dim i As Integer = 0
For Each row In dgrdServiceFailures.Rows
        dgrdServiceFailures.Rows(i).HeaderCell.Value = (1 + i).ToString
        i += 1
Next
dgrdServiceFailures.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)

Dim row2 As DataGridViewRow
Dim j As Integer = 0
For Each row2 In dgrdAcceptedSF.Rows
         dgrdAcceptedSF.Rows(j).HeaderCell.Value = (1 + j).ToString
         j += 1
Next
dgrdAcceptedSF.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)

Dim row3 As DataGridViewRow
Dim k As Integer = 0
For Each row3 In dgrdOutOfTimeSF.Rows
        dgrdOutOfTimeSF.Rows(k).HeaderCell.Value = (1 + k).ToString
        k += 1
Next
dgrdOutOfTimeSF.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)

 Dim row4 As DataGridViewRow
 Dim l As Integer = 0
 For Each row4 In dgrdRejectedSF.Rows
       dgrdRejectedSF.Rows(l).HeaderCell.Value = (1 + l).ToString
       l += 1
Next                    
dgrdRejectedSF.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)

Dim row5 As DataGridViewRow
Dim m As Integer = 0
For Each row5 In dgrdOutstandingSF.Rows
            dgrdOutstandingSF.Rows(m).HeaderCell.Value = (1 + m).ToString
             m + 1
 Next
dgrdOutstandingSF.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToFirstHeader)
0
 

Author Comment

by:Jimbo99999
ID: 39729218
Update:

I just cut and pasted the DataGrid from the second tab to the first tab where the DataGrid is that is getting the row numbers.  I sized them both smaller so I could could see the DateGrid that is getting RowNumbers and the the second DataGrid that is not getting RowNumbers.  

Without changing anything else, the second DataGrid now gets RowNumbers!
Then I cut and pasted the second DataGrid back to the second Tab  and now no RowNumbers!

Very interesting...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39729560
Seems like a .Net bug... I think I can't help you.
0
 

Author Comment

by:Jimbo99999
ID: 39729586
Good News!

 While I could load the last 4 tabs DataGrids with data while sitting on the first tab, I needed to be on the tab with the DataGrid that I wanted to set the RowNumbers on in order to be able to set the RowNumbers.  

So I use the following before code that sets the RowNumbers:

tabServiceFailure.SelectedIndex = 1

jimbo99999
0
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39729591
Anyway, it's a strange behaviour.

Congratulations!
0
 

Accepted Solution

by:
Jimbo99999 earned 0 total points
ID: 39729664
Thanks for your efforts and conversation.
0
 

Author Closing Comment

by:Jimbo99999
ID: 39737635
Found solution on my own.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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