[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-11-18
6
Medium Priority
?
294 Views
Last Modified: 2012-05-05
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
0
Comment
Question by:SGUDAPAT
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:kdwood
ID: 22986302
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
 
LVL 10

Expert Comment

by:kdwood
ID: 22986316
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
 
LVL 1

Author Comment

by:SGUDAPAT
ID: 22986392
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
Independent Software Vendors: 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 10

Expert Comment

by:kdwood
ID: 22986535
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
 
LVL 10

Accepted Solution

by:
kdwood earned 1500 total points
ID: 22986557
Also, make sure you put quotes around numLbl here:

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

0
 
LVL 1

Author Closing Comment

by:SGUDAPAT
ID: 31517871
Thanks a bunch for the solution.
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month19 days, 19 hours left to enroll

873 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