Datagrid View, Set Editing after loading defaults
-
Sunday, April 08, 2012 1:27 PM
Ran into this issue while debugging my data application. Now stumped.
Databound Datagrid1:
Fill row data with default values (all columns in the row)
but until I enter a row and change a value the row stays in the "default" state. Once enter a new value in any cell it then goes to the edit state.
I'll not bore with all the things I have tried, but none of them worked. hitting the f2 key....etc.
For now I just added an unlinked checkbox, check that and bingo I have what I want, but still a kluge.
Anyone have any ideas, that work?? :)
Thanks.
Ed Warren
Ed Warren Raising sails on masts not masts on sails
All Replies
-
Monday, April 09, 2012 9:10 AMModerator
How do you set the default value with which event, property or methods, please share us your demo to help you research your code, without your code it is hard to know where you did what, which makes this problem happen.
Please zip it and use the "SkyDrive".
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
Tuesday, April 10, 2012 9:44 AM
Thanks for your interest and help: I have inserted the code from the Datagrid default values needed event that I am using to set the default values.Private Sub SubsDataGridView_DefaultValuesNeeded(sender As System.Object, e As System.Windows.Forms.DataGridViewRowEventArgs) Handles SubsDataGridView.DefaultValuesNeeded 'Load default values into the subscription datagrid (default SubsCode from My.Settings, DatePaid: Today(), AmountPaid: Amount from SubsCode table, ExpiryDate: today+1year) e.Row.Cells(0).Value = My.Settings.DefaultSub e.Row.Cells(1).Value = Today() Dim dfltSubCode As dsLaa.SubsCodesRow dfltSubCode = DsLaa.SubsCodes.FindBySubsCodeID(My.Settings.DefaultSub) e.Row.Cells(2).Value = dfltSubCode.SubsFee e.Row.Cells(3).Value = DateAdd(DateInterval.Year, 1, Today()) End SubEd Warren Raising sails on masts not masts on sails
-
Tuesday, April 10, 2012 9:45 AM
Thanks for your interest and help: I have inserted the code from the Datagrid default values needed event that I am using to set the default values.Private Sub SubsDataGridView_DefaultValuesNeeded(sender As System.Object, e As System.Windows.Forms.DataGridViewRowEventArgs) Handles SubsDataGridView.DefaultValuesNeeded 'Load default values into the subscription datagrid (default SubsCode from My.Settings, DatePaid: Today(), AmountPaid: Amount from SubsCode table, ExpiryDate: today+1year) e.Row.Cells(0).Value = My.Settings.DefaultSub e.Row.Cells(1).Value = Today() Dim dfltSubCode As dsLaa.SubsCodesRow dfltSubCode = DsLaa.SubsCodes.FindBySubsCodeID(My.Settings.DefaultSub) e.Row.Cells(2).Value = dfltSubCode.SubsFee e.Row.Cells(3).Value = DateAdd(DateInterval.Year, 1, Today()) End SubEd Warren Raising sails on masts not masts on sails
-
Wednesday, April 11, 2012 7:26 AMModerator
The cells can be edited as expected.
Can you help me to ensure the code I share in this demo, or can you clarify the phenomena and question?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
-
Wednesday, April 11, 2012 10:17 AM
Again, thanks for your interest and help.
I agree the cells can be edited, and if one enters a cell and changes the value, all works as is should. However, If one gets the defaults values, then leaves the row without making a change, the cell is deleted and not saved. That is the behavior I'm trying to get around. If the user gets a new row through the getdefault action then I want to save the row data.
Ed Warren Raising sails on masts not masts on sails
-
Thursday, April 12, 2012 6:56 AMModerator
This is a the right behavior, too.
If you do not want it recover, then the only option you can do is use the CellLeave event handler to call the DataGridView.EndEdit method, this can make the DataGridView end this edit proceed and submit it, instead of just re-back.
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Edward Warren Thursday, April 12, 2012 10:26 AM
-
Thursday, April 12, 2012 10:27 AM
Thanks Mike, yes I know that is the "right" behavior, but I am looking for a way around it and I think you gave me the answer, thanks.
Ed Warren Raising sails on masts not masts on sails
-
Thursday, April 12, 2012 10:56 AMModerator


