Experiencing odd behavior when adding new row to datagridview (databound to bs)
-
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
-
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
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)
-
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)
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
-
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
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)
-
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)
-
Thanks Eddy!
"There's no such thing as a stupid question, only stupid people." - Mr. Garrison