Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB.Net - Adding Rows To DataGrid

Posted on 2013-12-18
8
Medium Priority
?
388 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

972 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