> private void SetTextBoxDatetimeBinding(TextBox txtbox, DataTable dt, string fieldname) > { > > Binding b = new Binding("Text", dt, fieldname); > { > b.Format += new ConvertEventHandler(DatetimeToString); > b.Parse += new ConvertEventHandler(DateTimeStringToDateTime); > } > txtbox.DataBindings.Clear(); > txtbox.DataBindings.Add(b); > > } > > private void DatetimeToString(object sender, ConvertEventArgs cevent) > { > // The method converts only to string type. Test this using the DesiredType. > if (cevent.DesiredType != typeof(string)) return; > > // Use the ToString method to format the value as currency ("c"). > cevent.Value = ((DateTime)cevent.Value).ToString("MM/dd/yy"); > } > > > private void DateTimeStringToDateTime(object sender, ConvertEventArgs cevent) > { > // The method converts back to decimal type only. > if (cevent.DesiredType != typeof(DateTime)) return; > > // Converts the string back to decimal using the static Parse method. > cevent.Value = DateTime.Parse(cevent.Value.ToString()); > } > > >