Solved

VB.Net - Adding Rows To DataGrid

Posted on 2013-12-18
8
355 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
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 39729560
Seems like a .Net bug... I think I can't help you.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

19 Experts available now in Live!

Get 1:1 Help Now