从绑定源在文本框中显示日期时间? [英] display datetime in textbox from bindingsource ?

查看:90
本文介绍了从绑定源在文本框中显示日期时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试格式化一个文本框,该文本框从bindingsource中获取数据

txtReportDate.DataBindings.Add("Text",dvHistory,开始日期")

我需要将txtReportDate显示为"dd/mm/yy"日期.有任何想法吗?

在此先感谢

Hi all,

I am trying to format a textbox which got data from bindingsource

txtReportDate.DataBindings.Add("Text", dvHistory, "Start Date")

I need to display the txtReportDate as a "dd/mm/yy" date. Any Ideas?

Thanks in advance

推荐答案

您可以更改区域性的默认设置:

You can change the default for the culture:

using System; 
using System.Globalization; 
using System.Threading;  
namespace test 
{     
  public static class Program 
  {         
    public static void Main() 
    {             
      CultureInfo culture = (CultureInfo)CultureInfo.CurrentCulture.Clone();
      culture.DateTimeFormat.ShortDatePattern = "dd-MMM-yyyy"; 
      culture.DateTimeFormat.LongTimePattern = "";  
      Thread.CurrentThread.CurrentCulture = culture;
      Console.WriteLine(DateTime.Now);
    }
  } 
} 


感谢回复人员:)
终于找到了解决方法
txtReportDate.DataBindings.Add("Text",dvHistory,开始日期",true,databaseupdatemode.never,","dd-MMM-yyyy")
thanks for reply guys :)
finally I found the solution
txtReportDate.DataBindings.Add("Text", dvHistory, "Start Date",true,databaseupdatemode.never,"","dd-MMM-yyyy")


这篇关于从绑定源在文本框中显示日期时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆