Solved

VB.Net - Adding Rows To DataGrid

Posted on 2013-12-18
8
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.

751 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