Dates and databinding

I bind my data to a textbox like this:

textBoxEndDate.DataBindings.Add("Text", ds.Tables["TestData"].DefaultView, "End date");


this gives me the date and the time (type DateTime in database). I prefer to see only the time. How do I do that

I'm have real difficulties with the dates, maybe you've noticied



Answer this question

Dates and databinding

  • FADI_KHAN

    I apologize for taking a bit to get back to you on this, you caught me after I had left the office yesterday.

    Now then, when binding your data with DataBindings.Add(), take a look at some of the overloads of it that exist, specifically the two with the most possible arguments and that allow you to specify a format string:

    public Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode, object nullValue, string formatString);

    public Binding Add(string propertyName, object dataSource, string dataMember, bool formattingEnabled, DataSourceUpdateMode updateMode, object nullValue, string formatString, IFormatProvider formatInfo);

    By specifying your own format based on the formatting options specified here you can achieve what you are looking for and would look something like this:

    textBoxEndDate.DataBindings.Add("Text", ds.Tables["TestData"].DefaultView, "End date", true, DataSourceUpdateMode.OnPropertyChanged, "No Date", "MM/dd/yyyy");



  • ramzi hawa

    Thank you so much!

    This really is extactly what I was looking for! I would never had found it on my own... thanks!


  • Dates and databinding