views:

348

answers:

2

i have a combobox which is displaying date from database...in my database the date enteries are in the format of mm/dd/yyyy but i want to display them in the format of dd-mm-yyyy...in that combobox..when the application run.

+1  A: 

If you can accept to have a global change in the app, set the CultureInfo.CurrentCulture to a European locale.

Timores
yes - or change the machine's regional and language settings.
Fakrudeen
how to accept answers im new to stackover
zoya
i appriciate the answers and replies but dnt know how to accept them
zoya
Have a look at: http://meta.stackoverflow.com/questions/5234/accepting-answers-what-is-it-all-about
Timores
thanks..now can u help me to sort out my current problem..im populating the dates in the combobox using data adapter and i want to convert the date format before loading the dates in the combobox..in c#.net ..is there any easy way out??
zoya
Add a column to your data table and use the code like in the answer above to populate that column in the format you like. Then bind your combo box to this new column instead of the original one.
Timores
+2  A: 

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";
Jojo Sardez
You can also use the FormatString property to control the format of the items. See http://msdn.microsoft.com/en-us/library/system.windows.forms.listcontrol.formatstring.aspx. This page has a link to a more detailed subject about formatting.
Ikaso
thanks for ur reply...can u tell me what is the procedure to convert the format for date when the values are populated in combobox using dataadapter...how could i convert the format before the dates are populated in the combobox..
zoya
@zoya - please check if the second code works for you. Thanks!
Jojo Sardez
im using data adapter and with the help of data set im entering the values in the table..and what do u mean by databing??
zoya
@zoya - oh its databinding sorry I mispelled it. are you looping the dataset's datatable - rows that contains the date and adds them 1 by 1? Please paste your code so I can find a way to fix it. Thanks
Jojo Sardez