Urgent--Set default value for the column in the data grid view

I have a data grid view populated with values from the database in my windows form.
I have added a new column in the data grid view, where I can enter the number of labels I want to print per item.
how can I set the default value of the column added by me(not from the database) to zero.
Private Sub GetDataForNPrnted()
        Dim numLbl As String
        Dim dt As New DataTable
        Dim DS As New DataSet
        'Select the data from the table and sets it to the dataset
        sSQL = "SELECT ID , LN_NBR, ITEM_ID" & _
              "FROM RECV_PRINT WHERE CODE = 'N' ORDER BY LINE_NO"
        If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RDGVW.DataSource = dt
                    With RDGVW.Columns
                        .Add(numLbl, "NUM. OF LABELS")
                    End With
                End If
            End With
        End If
    End Sub

Open in new window

code.doc
LVL 1
SGUDAPATAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kdwoodCommented:
There may be a cleaner way to do this, but here is one way that I know of:

Regards,

Keith
 


Private Sub GetDataForNPrnted()
        Dim numLbl As String
        Dim dt As New DataTable
        Dim DS As New DataSet
        'Select the data from the table and sets it to the dataset
        sSQL = "SELECT ID , LN_NBR, ITEM_ID" & _
              "FROM RECV_PRINT WHERE CODE = 'N' ORDER BY LINE_NO"
        If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RDGVW.DataSource = dt
                    With RDGVW.Columns
                        .Add(numLbl, "NUM. OF LABELS")
                    End With
                    
                    ' New Code
 
                      For Each row As DataGridViewRow In dgTest.Rows
                                row.Cells(numLbl).Value = 0
                      Next
 
                End If
            End With
        End If
    End Sub

Open in new window

0
kdwoodCommented:
oops, I have a type, try this instead:


Keith
 
 
 
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
 Private Sub GetDataForNPrnted()
        Dim numLbl As String
        Dim dt As New DataTable
        Dim DS As New DataSet
        'Select the data from the table and sets it to the dataset
        sSQL = "SELECT ID , LN_NBR, ITEM_ID" & _
              "FROM RECV_PRINT WHERE CODE = 'N' ORDER BY LINE_NO"
        If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RDGVW.DataSource = dt
                    With RDGVW.Columns
                        .Add(numLbl, "NUM. OF LABELS")
                    End With
                    
                    ' New Code
 
                      For Each row As DataGridViewRow In RDGVW.Rows
                           row.Cells(numLbl).Value = 0
                      Next
 
                 End If
            End With
        End If
    End Sub
 

Open in new window

0
SGUDAPATAuthor Commented:
HI Keith,

when I am added
For Each row As DataGridViewRow In RDGVW.Rows
                           row.Cells(numLbl).Value = 0
                      Next
 
in my code it is giving an "ArgumentNullException was unhandled-Value cannot be null.Parameter name:columnName" exception.
0
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

kdwoodCommented:
Greetings,

I looks like it's not finding your column name.  One thing I noticed in your code is that you are never stuffing a value into your "numLbl" variable.  You are declaring it as a string, but I don't see where you actually store anything to it.  So instead, try this:


Private Sub GetDataForNPrnted()
        Dim dt As New DataTable
        Dim DS As New DataSet
        'Select the data from the table and sets it to the dataset
        sSQL = "SELECT ID , LN_NBR, ITEM_ID" & _
              "FROM RECV_PRINT WHERE CODE = 'N' ORDER BY LINE_NO"
        If GetDataSet(DS, sSQL) Then
            With DS.Tables("Table")
                count = .Rows.Count
                If .Rows.Count > 0 Then
                    dt = DS.Tables("Table")
                    RDGVW.DataSource = dt
                    
                     With RDGVW.Columns
                        .Add("numLbl", "NUM. OF LABELS")  <--- changed here
                    End With
                    
                    ' New Code
 
                      For Each row As DataGridViewRow In RDGVW.Rows
                           row.Cells("numLbl").Value = 0
                      Next
 
                 End If
            End With
        End If
    End Sub
  
Open in New Window Select All 

Open in new window

0
kdwoodCommented:
Also, make sure you put quotes around numLbl here:

For Each row As DataGridViewRow In RDGVW.Rows
            row.Cells("numLbl").Value = 0
Next
 

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SGUDAPATAuthor Commented:
Thanks a bunch for the solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.