Dear All,

Here is my code i am generating data grid manually on run time i want to assign a default value to REC ST column, i have tried but it didn't assign default value please view the last line of this peace of code.

Dim clmprno As New DataGridViewTextBoxColumn
        clmprno.HeaderText = "PR NO"
        clmprno.DataPropertyName = "PR_NO"
        DataGridView1.Columns.Add(clmprno)

        Dim clmItemName As New DataGridViewTextBoxColumn
        clmItemName.HeaderText = "ITEM NAME"
        clmItemName.DataPropertyName = "ITEM"
        DataGridView1.Columns.Add(clmItemName)

        Dim clmqty As New DataGridViewTextBoxColumn
        clmqty.HeaderText = "QUANTITY"
        clmqty.DataPropertyName = "QTY"
        DataGridView1.Columns.Add(clmqty)


        Dim clmprr As New DataGridViewTextBoxColumn
        clmprr.HeaderText = "PUR REASON"
        clmprr.DataPropertyName = "PUR_REASON"
        DataGridView1.Columns.Add(clmprr)


        Dim clmPDate As New CalendarColumn
        clmPDate.HeaderText = "PR Date"
        clmPDate.DataPropertyName = "PR_DATE"
        DataGridView1.Columns.Add(clmPDate)


        Dim clmst As New DataGridViewComboBoxColumn
        clmst.HeaderText = "STATUS"
        clmst.DataPropertyName = "STATUS"
        DataGridView1.Columns.Add(clmst)
        clmst.MaxDropDownItems = 10
        clmst.Items.Add("IT")
        clmst.Items.Add("IT MANAGER")
        clmst.Items.Add("AITM")
        clmst.Items.Add("PM")
        clmst.Items.Add("SDF")

        Dim clmrst As New DataGridViewTextBoxColumn
        clmrst.HeaderText = "REC ST"
        clmrst.DataPropertyName = "REC_ST"
        DataGridView1.Columns.Add(clmrst)
        BindData()
        DataGridView1.DataSource = bindingsource1
        Label3.Text = Now
        Timer1.Enabled = True
        Timer1.Interval = 500
        DataGridView1.CurrentRow.Cells(4).Value = Now.ToString("MM/dd/yyyy")
        DataGridView1.CurrentRow.Cells(6).Value = "NEW"

When i tried this code

Dim clmrst As New DataGridViewTextBoxColumn
clmrst.HeaderText = "REC ST"
clmrst.DataPropertyName = "REC_ST"
clmrst.DefaultCellStyle.NullValue = "New"
clmrst.DefaultCellStyle.DataSourceNullValue = "New"
DataGridView1.Columns.Add(clmrst)

It shows default value but when i try to save it didn't saved in the db here is my save code

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Try
            For r = 0 To DataGridView1.RowCount - 2 ' Why RowCount-2?
                For Each cell As DataGridViewCell In DataGridView1.Rows(r).Cells
                    If cell.FormattedValue Is Nothing OrElse cell.FormattedValue.ToString = String.Empty Then
                        MessageBox.Show("Please Enter the Required Field(s)!", "ITPCHR", MessageBoxButtons.OK, MessageBoxIcon.Stop)
                        Exit Sub ' This will exit the sub and not show multiple messageboxes (which in my opinion is pretty irritating to the user)
                    End If
                Next
            Next r
            ' Only Update your changes to the Database if there are no errors
            Me.Validate()
            Me.myDA.Update(Me.mydataset.Tables("PR_REC"))
            BindData()
            MessageBox.Show("Record Inserted Successfully......", "ITPCHR", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

Just a few questions:
1) Did you defined the insert update and delete commands of your data adapter?
2) Wich is the currentrow value?

Hope this helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.