Formatting Bound ComboBox with DateTime

  • Thread starter Thread starter David Adams
  • Start date Start date
D

David Adams

Hi,

I have a bound ComboBox that has a DateTime field for the DisplayMember. I
only want the date to show instead of the date and time (always 12:00 AM).
Is it possible to format the DisplayMember property of the ComboBox?

Thanks,

David Adams
 
You didn't state what the datasource was...but if you can override the
ToString method on the datasource to return just the date part, that's
one option. In the past I've also created a duplicate column on the
datasource (in cases where there's not much data and this isn't a
problem) of type String and initialized to the formatted text as I need
it. This works well for SQL Server queries in DataSets.

The Binding object has a Format event where you can tell it how to
format your data by type. Unfortunately it's not of much help for the
ComboBox list portion...
 
Thank you all for your suggestions.

David



Jim-M said:
You didn't state what the datasource was...but if you can override the
ToString method on the datasource to return just the date part, that's
one option. In the past I've also created a duplicate column on the
datasource (in cases where there's not much data and this isn't a
problem) of type String and initialized to the formatted text as I need
it. This works well for SQL Server queries in DataSets.

The Binding object has a Format event where you can tell it how to
format your data by type. Unfortunately it's not of much help for the
ComboBox list portion...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top