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. C#
  4. form controls default values

form controls default values

Scheduled Pinned Locked Moved C#
questiondatabase
4 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.
  • L Offline
    L Offline
    LordZoster
    wrote on last edited by
    #1

    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)

    L 1 Reply Last reply
    0
    • L LordZoster

      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)

      L Offline
      L Offline
      LordZoster
      wrote on last edited by
      #2

      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. "

      L 1 Reply Last reply
      0
      • L LordZoster

        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. "

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        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.

        L 1 Reply Last reply
        0
        • L Luc Pattyn

          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.

          L Offline
          L Offline
          LordZoster
          wrote on last edited by
          #4

          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;
              }
            }
          }
          
          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