Adding row to dataview
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Adding row to dataview

  1. #1
    Join Date
    May 2012
    Posts
    2

    Adding row to dataview

    Hi, i am trying to add several rows to a dataview before bindng it to the datagridview. I have tried several variations of the below code but only the last row will actuall load into the grid. Probably doing something stupid. Any help will be appreciated.

    My code is:

    dvInspectDetail.AllowNew = True
    Dim newRow1 As DataRowView = dvInspectDetail.AddNew
    newRow1("IDetail") = mDetailNo.ToString
    newRow1("IDDescr") = "Kiddi count = " & mKiddi
    newRow1("IDRate1") = False
    newRow1("IDRate2") = False
    newRow1("IDRate3") = False
    'newRow1.EndEdit()
    Dim newRow2 As DataRowView = dvInspectDetail.AddNew
    newRow2("IDetail") = mDetailNo.ToString
    newRow2("IDDescr") = "Midi count = " & mMidi
    newRow2("IDRate1") = False
    newRow2("IDRate2") = False
    newRow2("IDRate3") = False
    'newRow2.EndEdit()
    Dim newRow3 As DataRowView = dvInspectDetail.AddNew
    newRow3("IDetail") = mDetailNo.ToString
    newRow3("IDDescr") = "Maxi count = " & mMaxi
    newRow3("IDRate1") = False
    newRow3("IDRate2") = False
    newRow3("IDRate3") = False
    'newRow3.EndEdit()
    Dim newRow4 As DataRowView = dvInspectDetail.AddNew
    newRow4("IDetail") = mDetailNo.ToString
    newRow4("IDDescr") = "Jumbo count = " & mJumbo
    newRow4("IDRate1") = False
    newRow4("IDRate2") = False
    newRow4("IDRate3") = False
    'newRow4.EndEdit()
    Dim newRow5 As DataRowView = dvInspectDetail.AddNew
    newRow5("IDetail") = mDetailNo.ToString
    newRow5("IDDescr") = mComment
    newRow5("IDRate1") = False
    newRow5("IDRate2") = False
    newRow5("IDRate3") = False
    'newRow5.EndEdit()
    MsgBox(dvInspectDetail.Count)

    dgvInspectDetail.DataSource = dvInspectDetail

    Many thanks in advance.

    Alwyn

  2. #2
    Join Date
    May 2012
    Posts
    2

    Re: Adding row to dataview

    Several hours later and i still cant figure this one out. What i have found is that only one row will add to the dataview (irrespective if you dim the rows the same or different variables) and only the last parameter sent will be updated in the row. I have tried it in a for next loop, but makes no difference. There is also no .update or .acceptchanges to force the row update after each new rowadd. Interesting is that if i uncomment the .endedit, then no rows are added to the dataview.

    I am hoping that my learned colleaguesout there can figure this one out.

    Tx
    Alwyn

  3. #3
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Adding row to dataview

    Need to UPDATE each row, or SAVE it each time... Depends how the table is bound.

    Why not just enter it into an unbound form?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

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


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center