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

"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.

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

Keith1: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

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 SubOpen in New Window Select All