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. Experiencing odd behavior when adding new row to datagridview (databound to bs)

Experiencing odd behavior when adding new row to datagridview (databound to bs)

Scheduled Pinned Locked Moved Visual Basic
questionhelp
6 Posts 2 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.
  • J Offline
    J Offline
    Jon_Boy
    wrote on last edited by
    #1

    The bright side - it's Friday :) I have a datagridview that is databound with a bindingsource to a strongly typed dataset. There are 5 columns: 2 text fields, 2 combos (that have a datarelation to child tables) and a checkbox. If I click to add a new row and manually type\select values - every thing works as expected. Meaning, as I am filling in data, there is another blank row below that is added. To help streamline data entry, I want to specify default values for the fields. If I attempt to default values via dgv_DefaultValuesNeeded or the bs.AddingNew: All the default values are displayed correctly - but a new blank row isn't added to the end of the datagridview. The last visible row (has all values defaulted correctly) but there isn't a blank line below? If I double click a combobox (don't even change the value - just double click it) or click the checkbox, then the change is reflected properly to the bindingsource and a new black line is added below? I'm not sure what is going on. The comboboxes are set properly because the DisplayMember values are correct. If I click a previous row (without clicking the checkbox or selecting a combobox) the new row is removed as well - which makes it seem like it's not actually being added to the bindingsource during the AddingNew event. Very stumped on this. Curious if anyone else has run into this. Probably missing something overly simple.

    Private Sub bsPlantLocSub_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles bsPlantLocSub.AddingNew
    Dim strTemp As String = GetNewDefaultValue_LabelPrefix()

    dsLocSetup.DataTable\_PlantLocSub.PlantLocationIDColumn.DefaultValue = \_Default\_PlantLocID
    dsLocSetup.DataTable\_PlantLocSub.LabelPrefixColumn.DefaultValue = strTemp
    dsLocSetup.DataTable\_PlantLocSub.LocationSubColumn.DefaultValue = "Location:" & Strings.Right(strTemp, 4)
    dsLocSetup.DataTable\_PlantLocSub.ComponentStatusColumn.DefaultValue = "IC"
    dsLocSetup.DataTable\_PlantLocSub.SysLocOnlyColumn.DefaultValue = False
    bsPlantLocSub.MoveLast()
    

    End Sub

    I had also tried this in the bs.AddingNew - same behavior as listed above.

        Dim dv As DataView = TryCast(bsPlantLocSub.List, DataView)
        Dim drv As DataRowView = dv.AddNew
        Dim strTemp As String = GetNewDefaultValue\_LabelPrefix()
    
        drv("PlantLocationID") = \_Default\_PlantLocID
        drv("LabelPrefix") = strTemp
        drv("LocationSub") = "Location:" & St
    
    L 1 Reply Last reply
    0
    • J Jon_Boy

      The bright side - it's Friday :) I have a datagridview that is databound with a bindingsource to a strongly typed dataset. There are 5 columns: 2 text fields, 2 combos (that have a datarelation to child tables) and a checkbox. If I click to add a new row and manually type\select values - every thing works as expected. Meaning, as I am filling in data, there is another blank row below that is added. To help streamline data entry, I want to specify default values for the fields. If I attempt to default values via dgv_DefaultValuesNeeded or the bs.AddingNew: All the default values are displayed correctly - but a new blank row isn't added to the end of the datagridview. The last visible row (has all values defaulted correctly) but there isn't a blank line below? If I double click a combobox (don't even change the value - just double click it) or click the checkbox, then the change is reflected properly to the bindingsource and a new black line is added below? I'm not sure what is going on. The comboboxes are set properly because the DisplayMember values are correct. If I click a previous row (without clicking the checkbox or selecting a combobox) the new row is removed as well - which makes it seem like it's not actually being added to the bindingsource during the AddingNew event. Very stumped on this. Curious if anyone else has run into this. Probably missing something overly simple.

      Private Sub bsPlantLocSub_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles bsPlantLocSub.AddingNew
      Dim strTemp As String = GetNewDefaultValue_LabelPrefix()

      dsLocSetup.DataTable\_PlantLocSub.PlantLocationIDColumn.DefaultValue = \_Default\_PlantLocID
      dsLocSetup.DataTable\_PlantLocSub.LabelPrefixColumn.DefaultValue = strTemp
      dsLocSetup.DataTable\_PlantLocSub.LocationSubColumn.DefaultValue = "Location:" & Strings.Right(strTemp, 4)
      dsLocSetup.DataTable\_PlantLocSub.ComponentStatusColumn.DefaultValue = "IC"
      dsLocSetup.DataTable\_PlantLocSub.SysLocOnlyColumn.DefaultValue = False
      bsPlantLocSub.MoveLast()
      

      End Sub

      I had also tried this in the bs.AddingNew - same behavior as listed above.

          Dim dv As DataView = TryCast(bsPlantLocSub.List, DataView)
          Dim drv As DataRowView = dv.AddNew
          Dim strTemp As String = GetNewDefaultValue\_LabelPrefix()
      
          drv("PlantLocationID") = \_Default\_PlantLocID
          drv("LabelPrefix") = strTemp
          drv("LocationSub") = "Location:" & St
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I could lookup the DataGridView on MSDN and check, but in this case I am wondering whether you know what to expect from the default behaviour.

      Jon_Boy wrote:

      The last visible row (has all values defaulted correctly) but there isn't a blank line below?

      The new row with default-values is what you wanted, not an empty row. Make changes in that row and save it.

      Jon_Boy wrote:

      but a new blank row isn't added to the end of the datagridview.

      An extra blank row would make the ones with the default values redundant. Overwrite any values you want there and save.

      Jon_Boy wrote:

      If I double click a combobox (don't even change the value - just double click it) or click the checkbox, then the change is reflected properly to the bindingsource and a new black line is added below?

      Means you edited the row, and by changing focus it will be updating the bindingsource.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

      J 1 Reply Last reply
      0
      • L Lost User

        I could lookup the DataGridView on MSDN and check, but in this case I am wondering whether you know what to expect from the default behaviour.

        Jon_Boy wrote:

        The last visible row (has all values defaulted correctly) but there isn't a blank line below?

        The new row with default-values is what you wanted, not an empty row. Make changes in that row and save it.

        Jon_Boy wrote:

        but a new blank row isn't added to the end of the datagridview.

        An extra blank row would make the ones with the default values redundant. Overwrite any values you want there and save.

        Jon_Boy wrote:

        If I double click a combobox (don't even change the value - just double click it) or click the checkbox, then the change is reflected properly to the bindingsource and a new black line is added below?

        Means you edited the row, and by changing focus it will be updating the bindingsource.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

        J Offline
        J Offline
        Jon_Boy
        wrote on last edited by
        #3

        Hey Eddy, If all columns have defaulted values, wouldn't simply pressing tab on that row cause the new (blank) row to be added below? Why would a combo need to be selected or a text field need to go into edit mode to force the new row? I tried to force a cell into edit mode after defaultvaluesneeded, but it causes a re-entrant condition, so the users is forced to do this. Not a huge deal, but am a little confused when all the values are present.

        "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

        L 1 Reply Last reply
        0
        • J Jon_Boy

          Hey Eddy, If all columns have defaulted values, wouldn't simply pressing tab on that row cause the new (blank) row to be added below? Why would a combo need to be selected or a text field need to go into edit mode to force the new row? I tried to force a cell into edit mode after defaultvaluesneeded, but it causes a re-entrant condition, so the users is forced to do this. Not a huge deal, but am a little confused when all the values are present.

          "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Jon_Boy wrote:

          If all columns have defaulted values, wouldn't simply pressing tab on that row cause the new (blank) row to be added below?

          I'd expect it to move the focus to the next control, as specified in the TabOrder.

          Jon_Boy wrote:

          Why would a combo need to be selected or a text field need to go into edit mode to force the new row?

          ..because you didn't edit anything. Press F2 to edit, ESC to cancel those edits. If you don't want that behaviour, set the EditMode[^] to DataGridViewEditMode.EditOnEnter.

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

          J 1 Reply Last reply
          0
          • L Lost User

            Jon_Boy wrote:

            If all columns have defaulted values, wouldn't simply pressing tab on that row cause the new (blank) row to be added below?

            I'd expect it to move the focus to the next control, as specified in the TabOrder.

            Jon_Boy wrote:

            Why would a combo need to be selected or a text field need to go into edit mode to force the new row?

            ..because you didn't edit anything. Press F2 to edit, ESC to cancel those edits. If you don't want that behaviour, set the EditMode[^] to DataGridViewEditMode.EditOnEnter.

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

            J Offline
            J Offline
            Jon_Boy
            wrote on last edited by
            #5

            Thanks Eddy!

            "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

            L 1 Reply Last reply
            0
            • J Jon_Boy

              Thanks Eddy!

              "There's no such thing as a stupid question, only stupid people." - Mr. Garrison

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              You're welcome :)

              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