form controls default values
-
Hallo I have the typical case of a form with some controls bound to a bindingsource (backed by a database). If the control default value is somewhat acceptable for the user (eg. a dtp shows the current date or a check box is unchecked) he lets them untouched, assuming their values will be written as is in the database. But this doesn't happen: if a control isn't touched by a user, it is ignored by bindingSource's EndEdit method. How can I avoid this? (I suppose this have already been discussed in many places, but I cannot find references, maybe I'm Googling with wrong keywords)
-
Hallo I have the typical case of a form with some controls bound to a bindingsource (backed by a database). If the control default value is somewhat acceptable for the user (eg. a dtp shows the current date or a check box is unchecked) he lets them untouched, assuming their values will be written as is in the database. But this doesn't happen: if a control isn't touched by a user, it is ignored by bindingSource's EndEdit method. How can I avoid this? (I suppose this have already been discussed in many places, but I cannot find references, maybe I'm Googling with wrong keywords)
I found the answer at http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-ado-net/18455/Binding-DateTimePicker[^] Specifically: "Bart Mermuys - 28 Dec 2006 12:06 GMT [...] well it's the Binding that has a (private) modified flag which is triggered by the Control property-Changed event (eg. TextChanged/ValueChanged). The value isn't persisted if the modified flag hasn't been set. [...]Try to set default values on the DataSource. [...]If you're using NET2.0 you can use the DataTable.TableNewRow event. "
-
I found the answer at http://www.dotnetmonster.com/Uwe/Forum.aspx/dotnet-ado-net/18455/Binding-DateTimePicker[^] Specifically: "Bart Mermuys - 28 Dec 2006 12:06 GMT [...] well it's the Binding that has a (private) modified flag which is triggered by the Control property-Changed event (eg. TextChanged/ValueChanged). The value isn't persisted if the modified flag hasn't been set. [...]Try to set default values on the DataSource. [...]If you're using NET2.0 you can use the DataTable.TableNewRow event. "
thanks for sharing this. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
-
thanks for sharing this. :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
you're welcome. For completeness sake, I'm posting a snippet about it:
void defValues(DataTable dt) { foreach (DataColumn dc in dt.Columns) { switch (dc.DataType.ToString()) { case "System.DateTime": //datetime dc.DefaultValue = DEFAULT\_DT; break; case "System.Boolean": //checkboxes, bit values ecc dc.DefaultValue = false; break; default: break; } } }