Solved

VB.Net - Adding Rows To DataGrid

Posted on 2013-12-18
8
351 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

8 Experts available now in Live!

Get 1:1 Help Now