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.
views:
348answers:
2
+1
A:
If you can accept to have a global change in the app, set the CultureInfo.CurrentCulture to a European locale.
Timores
2010-02-26 06:50:00
yes - or change the machine's regional and language settings.
Fakrudeen
2010-02-26 06:56:51
how to accept answers im new to stackover
zoya
2010-02-26 07:20:00
i appriciate the answers and replies but dnt know how to accept them
zoya
2010-02-26 07:20:35
Have a look at: http://meta.stackoverflow.com/questions/5234/accepting-answers-what-is-it-all-about
Timores
2010-02-26 08:15:33
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
2010-02-26 08:49:10
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
2010-02-26 08:57:23
+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
2010-02-26 06:58:59
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
2010-02-26 07:25:32
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
2010-02-26 08:39:03
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
2010-02-26 09:07:45
@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
2010-02-26 09:21:47