简体   繁体   中英

how to change the date format from mm/dd/yyyy to dd-mm-yyyy in combobox?

我有一个组合框显示数据库中的日期...在我的数据库中,日期输入项的格式为mm / dd / yyyy,但是我想以dd-mm-yyyy ...的格式显示它们。 ..当应用程序运行时。

You can either convert the format of your date before you load them to the combo box or run this code after the combobox have been filled:

for (int index = 0; index < this.comboBox1.Items.Count; index++)
        {
            this.comboBox1.Items[index] = DateTime.Parse(this.comboBox1.Items[index].ToString()).ToString("dd-mm-yyyy");
        }

Edited:

If your are using databinding and sure that the type of data being displayed is date. Try this:

 this.comboBox1.FormatString = "dd-MM-yyyy";

如果您接受在应用程序中进行全局更改,则将CultureInfo.CurrentCulture设置为欧洲语言环境。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM