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...
 
Back
Top