Datagrid View, Set Editing after loading defaults
-
8 aprilie 2012 13:27
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
Toate mesajele
-
9 aprilie 2012 09:10Moderator
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
-
10 aprilie 2012 09:44
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
-
10 aprilie 2012 09:45
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
-
11 aprilie 2012 07:26Moderator
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
-
11 aprilie 2012 10:17
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
-
12 aprilie 2012 06:56Moderator
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
- Marcat ca răspuns de Edward Warren 12 aprilie 2012 10:26
-
12 aprilie 2012 10:27
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
-
12 aprilie 2012 10:56Moderator