Results 1 to 2 of 2

Thread: VB.NET 2005 - Datagridview - Update cell value with code

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    VB.NET 2005 - Datagridview - Update cell value with code

    Hi,

    I have a Datagridview with containing 9 columns.

    Column #2 is hidden and remains blank until the user presses a given button on my WinForm. At that moment, I have to go put a value in column #2 for all the rows of my datagridview and save.

    Dataset (dtsData) is the datasource of the datagridview (grdInfo)

    Here is what I tried:
    Code:
    For i = 0 To grdInfo.Rows.Count - 1
       grdInfo.Rows(i).Cells("idDossierDisciplinaireEntete").Value = 6       '(6 is just a sample value for the use of my question)
    Next
    
    If dtsData.HasChanges Then
       intRet = sqlAdaptor.Update(dtsData)
    End If
    The "sqlAdaptor.Update(dtsData) doesn't work because the grid cell I just updated doesn't seem to retain the new value. And in my UpdateCommand that column is a mandatory field in my database table. The update tells my I can't insert NULL which is true, but the value should be 6, not NULL.

    After the Cells("idDossierDisciplinaireEntete") affectation I tried this:
    Code:
    grdInfo.UpdateCellValue(grdInfo.Rows(i).Cells("idDossierDisciplinaireEntete").ColumnIndex, i)
    It didn't help
    I tried this:
    Code:
    grdInfo.RefreshEdit()
    It didn't help either.

    Anyone can help me.
    Thank you

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2004
    Posts
    369

    Re: VB.NET 2005 - Datagridview - Update cell value with code

    I use this code instead. Seems to work ..

    Code:
                                For i = 0 To dtsData.Tables(0).Rows.Count - 1
                                    dtsData.Tables(0).Rows(i).BeginEdit()
                                    dtsData.Tables(0).Rows(i).Item("idDossierDisciplinaireEntete") = 6
                                    dtsData.Tables(0).Rows(i).EndEdit()
                                Next
    
                            If dtsData.HasChanges Then
                                intRet = sqlAdaptor.Update(dtsData)
                            End If

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width