Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Datagridview add new rows -- Error

Datagridview add new rows -- Error

Scheduled Pinned Locked Moved Visual Basic
helpcssdatabasewpfwcf
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Chrispie123
    wrote on last edited by
    #1

    Hi I am having the following problem with a data grid (This is my child grid). My data grid is bound to a binding source which is bounded to a dataset filled with data. I want the user to be able to add new rows and as they add rows certain fields needs to be populated (There fields is not visible in my grid) with data from my parent dataset. I add the data in the following handler

    AddHandler dataset.table.TableNewRow, AddressOf AddNewPreRow

    Private Sub AddNewPrePopulatedWarehouseLocationRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
    e.Row.Item("ColumnName") = CStr(SelectedParentRow.ColumnName)
    End Sub

    If the user moves to a new row the values is populated (if I make the invisible columns visible I can see that they do get populated) and if the user goes back the row disappears like i want to. I also do a validation on the CellEndEdit and in here I make use of the rowindex. But the problem comes when the user goes to the new line enter a value in the first cell (By this time the dgv seems to be taking this as a new row and it is not "Dirty anymore" And it shows a new line with * beneath this line) which is all ok..... This far we have 2 lines - 1. The line that i just created and added info into the first column (This line has a pencil next to it) 2. An empty line beneath it (This line has a * next to it) If i use the mouse and click on another row 1. The newly add line with the pencil next to it cleans itself (I suppose this is because i did not enter all the required fields yet and the data binding discards the data) But the empty line remains there 2. Now the validation fires for this line and a get a Index <XX> does not have a value 3. There is now 2 empty lines then new one now has a Play button sign and the line beneath it has a * In my validation i check for the following to execute validation

    If (dgv.Rows(RowIndex) IsNot Nothing) AndAlso Not dgv.Rows(RowIndex).IsNewRow AndAlso dgv.IsCurrentRowDirty Then --> result in true

    Please if someone knows how to fix this i will appreciate it. Thanks, Chris

    M D 2 Replies Last reply
    0
    • C Chrispie123

      Hi I am having the following problem with a data grid (This is my child grid). My data grid is bound to a binding source which is bounded to a dataset filled with data. I want the user to be able to add new rows and as they add rows certain fields needs to be populated (There fields is not visible in my grid) with data from my parent dataset. I add the data in the following handler

      AddHandler dataset.table.TableNewRow, AddressOf AddNewPreRow

      Private Sub AddNewPrePopulatedWarehouseLocationRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
      e.Row.Item("ColumnName") = CStr(SelectedParentRow.ColumnName)
      End Sub

      If the user moves to a new row the values is populated (if I make the invisible columns visible I can see that they do get populated) and if the user goes back the row disappears like i want to. I also do a validation on the CellEndEdit and in here I make use of the rowindex. But the problem comes when the user goes to the new line enter a value in the first cell (By this time the dgv seems to be taking this as a new row and it is not "Dirty anymore" And it shows a new line with * beneath this line) which is all ok..... This far we have 2 lines - 1. The line that i just created and added info into the first column (This line has a pencil next to it) 2. An empty line beneath it (This line has a * next to it) If i use the mouse and click on another row 1. The newly add line with the pencil next to it cleans itself (I suppose this is because i did not enter all the required fields yet and the data binding discards the data) But the empty line remains there 2. Now the validation fires for this line and a get a Index <XX> does not have a value 3. There is now 2 empty lines then new one now has a Play button sign and the line beneath it has a * In my validation i check for the following to execute validation

      If (dgv.Rows(RowIndex) IsNot Nothing) AndAlso Not dgv.Rows(RowIndex).IsNewRow AndAlso dgv.IsCurrentRowDirty Then --> result in true

      Please if someone knows how to fix this i will appreciate it. Thanks, Chris

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      sorry I'm not going to be able to help I gave up on grid editing in VB5. I use a different design paradign, Grids are stupid, they are ONLY used for displaying and sorting lists. I used to use listviews but a grid is actually faster loading. I then add a context menu for Add/Edit/Delete which open a seperate dialog where the user does the CRUD work. When the user returns the grid is repopulated from the database. This eliminates ALL the hassles you have around user interaction with the grid and which events to handle. Think about the DetailBlock in ASPx. the only issues is reloading the DGV and the inevitable flash as it reloads

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • C Chrispie123

        Hi I am having the following problem with a data grid (This is my child grid). My data grid is bound to a binding source which is bounded to a dataset filled with data. I want the user to be able to add new rows and as they add rows certain fields needs to be populated (There fields is not visible in my grid) with data from my parent dataset. I add the data in the following handler

        AddHandler dataset.table.TableNewRow, AddressOf AddNewPreRow

        Private Sub AddNewPrePopulatedWarehouseLocationRow(ByVal sender As Object, ByVal e As System.Data.DataTableNewRowEventArgs)
        e.Row.Item("ColumnName") = CStr(SelectedParentRow.ColumnName)
        End Sub

        If the user moves to a new row the values is populated (if I make the invisible columns visible I can see that they do get populated) and if the user goes back the row disappears like i want to. I also do a validation on the CellEndEdit and in here I make use of the rowindex. But the problem comes when the user goes to the new line enter a value in the first cell (By this time the dgv seems to be taking this as a new row and it is not "Dirty anymore" And it shows a new line with * beneath this line) which is all ok..... This far we have 2 lines - 1. The line that i just created and added info into the first column (This line has a pencil next to it) 2. An empty line beneath it (This line has a * next to it) If i use the mouse and click on another row 1. The newly add line with the pencil next to it cleans itself (I suppose this is because i did not enter all the required fields yet and the data binding discards the data) But the empty line remains there 2. Now the validation fires for this line and a get a Index <XX> does not have a value 3. There is now 2 empty lines then new one now has a Play button sign and the line beneath it has a * In my validation i check for the following to execute validation

        If (dgv.Rows(RowIndex) IsNot Nothing) AndAlso Not dgv.Rows(RowIndex).IsNewRow AndAlso dgv.IsCurrentRowDirty Then --> result in true

        Please if someone knows how to fix this i will appreciate it. Thanks, Chris

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        I agree with Mycroft. I try not to allow any editing in a DGV, unless absolutely necessary. Using a seperate data entry form gives you more flexibility and maintainability with lower cost in code.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        C 1 Reply Last reply
        0
        • D Dave Kreskowiak

          I agree with Mycroft. I try not to allow any editing in a DGV, unless absolutely necessary. Using a seperate data entry form gives you more flexibility and maintainability with lower cost in code.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          C Offline
          C Offline
          Chrispie123
          wrote on last edited by
          #4

          Hi Thanks for your comments. :) Appreciate it. The reason why I want to use grids is because I have 2 tabs on my form.... Summary And Detail tabs. The summary is an Overview of my header (DGV) and the details display the parked line of the summary tab with some more information in text/combo/check.... Below that I have another tab control with child related information. ....for argument sake... I have a Summary Tab that displays Lecturers at a varsity. A details tab with more information about the lecturer. Below that I have a tab controls with tabs about which classes does this lecturer have... If I make this a separate window again I think the form will be too cluttered. What I have done in the mean time (but I think it is dodgy coding) is catching a IndexOutOfRange exception and do nothing about it. Thanks, Chris

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups