dagpcs
asked on
How do you format a date as MM/DD/YYYY (without the time) when using DataBinding?
What is the best way to format the date as MM/DD/YYYY (without the time) when using DataBinding? We have a DataTable that contains a date column which is bound to a column in a DataGrid. Additionally, when a row of the DataGrid has focus, the contents of the Date cell is also displayed in a TextBox using the TextBox 'DataBindings Property'. The value in the TextBox is modifiable. What would be the best way to format the date and have it represented as desired in all 3 locations?
ASKER
Thank you for your prompt response. We are using tablestyle but find that adding myTextBoxColumn1.Format = "MM/dd/yyyy" to that column formats the date correctly in the datagrid. However, a textbox is also bound to the same datasource and there the time is still displaying. Do you have any additional suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dim myGridTableStyle As DataGridTableStyle = New DataGridTableStyle
myGridTableStyle.MappingNa
DataGrid1.TableStyles.Clea
DataGrid1.TableStyles.Add(
'ColumnNumber is the datetime column number
Dim myTextBoxColumn1 As DataGridTextBoxColumn = DataGrid1.TableStyles(0).G
myTextBoxColumn1.Format = "MM/dd/yyyy"
If you are using table style, just add myTextBoxColumn1.Format = "MM/dd/yyyy" to that column.