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. Date in DataBinding

Date in DataBinding

Scheduled Pinned Locked Moved C#
questiondatabasehelp
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.
  • A Offline
    A Offline
    alee15 10 88
    wrote on last edited by
    #1

    Hi everyone, I have a problem re: DataBindings. I binded a textbox with a database in which I would like to show the date in it, but unfortunately I can't remove the time, so that in the textbox the date only is shown. How can I do it? The following is the code I used for databinding. this.txtDOB.DataBindings.Add("Text", DBHandler.DS, "UserLogInsteacher.DateOfBirth"); Thanks a lot!!

    R 1 Reply Last reply
    0
    • A alee15 10 88

      Hi everyone, I have a problem re: DataBindings. I binded a textbox with a database in which I would like to show the date in it, but unfortunately I can't remove the time, so that in the textbox the date only is shown. How can I do it? The following is the code I used for databinding. this.txtDOB.DataBindings.Add("Text", DBHandler.DS, "UserLogInsteacher.DateOfBirth"); Thanks a lot!!

      R Offline
      R Offline
      Robert Rohde
      wrote on last edited by
      #2

      The Add call returns a Binding[^] object which has a Format[^] event. Use it to format your data.

      A 1 Reply Last reply
      0
      • R Robert Rohde

        The Add call returns a Binding[^] object which has a Format[^] event. Use it to format your data.

        A Offline
        A Offline
        alee15 10 88
        wrote on last edited by
        #3

        I didn't understand you quite well. How can I do that?

        R 1 Reply Last reply
        0
        • A alee15 10 88

          I didn't understand you quite well. How can I do that?

          R Offline
          R Offline
          Robert Rohde
          wrote on last edited by
          #4

          Something like this (not tested):

          Binding binding = this.txtDOB.DataBindings.Add("Text", DBHandler.DS, "UserLogInsteacher.DateOfBirth");
          binding.Format += new ConvertEventHandler(binding_Format);

          and

          private void binding_Format(object sender, ConvertEventArgs e)
          {
          DateTime dt = (DateTime)e.Value;
          e.Value = dt.ToShortDateString();
          }

          Some error handling etc should be added (like checking for DbNull etc.)

          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