We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Format Date/Time Column in Datagrid

Thread ID:





350 Jun 9,2002 07:35 AM UTC Jun 10,2002 11:49 AM UTC WinForms 3
Tags: FAQ
Administrator [Syncfusion]
Asked On June 9, 2002 07:35 AM UTC

My Access db has a field type Date/Time. When I bind the grid, the field shows the date and the time even if i don't have the time specified in the db! It automatically add a time and same if if have a time field it adds a date! That's insane!! I tried the code in the FAQ area but doesn't work.. what's wrong? I want the second column of my grid to show the time only (without the date) and the third column of my grid to show just the date with no time! Dim myCurrencyMngr As CurrencyManager Dim dgtbc As New DataGridTextBoxColumn() myCurrencyMngr = CType(BindingContextdsEmployee, "Employee"), CurrencyManager) dgts = New DataGridTableStyle(myCurrencyMngr) myGrid.TableStyles.Add(dgts) dgts.MappingName = "Employee" dgts.AlternatingBackColor = Color.Honeydew dgtbc = myGrid.TableStyles(0).GridColumnStyles(1) dgtbc.Format = "h:mm"

Clay Burch [Syncfusion]
Replied On June 9, 2002 12:27 PM UTC

This code works OK for me. It causes the grid to display minutes and seconds only in column 4. The only difference I see is that it uses the new table style to access all the columns styles whereas in your code, you access the columnstyle to set the format through the datagrid.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'add a datasource to the grid
        Me.DataGrid1.DataSource = Nothing
        SqlDataAdapter1.Fill(Me.DataSet11, "FAQEntries")
        Me.DataGrid1.DataSource = Me.DataSet11.Tables("FAQEntries")

        'create a tablestyle based on the current contents
        Dim myCurrencyManager As CurrencyManager
        myCurrencyManager = CType(BindingContext(Me.DataSet11, "FAQEntries"), CurrencyManager)
        Dim ts As DataGridTableStyle
        ts = New DataGridTableStyle(myCurrencyManager)
        'add the tablestyle to grid

        'modify particular columnstyles in the tablestyle
        ts.GridColumnStyles(1).Alignment = HorizontalAlignment.Right
        ts.GridColumnStyles(2).Width = 30
        ts.GridColumnStyles(4).HeaderText = "test"
        CType(ts.GridColumnStyles(4), DataGridTextBoxColumn).Format = "h:mm"
End Sub

Administrator [Syncfusion]
Replied On June 10, 2002 05:50 AM UTC

CType(ts.GridColumnStyles(4), DataGridTextBoxColumn).Format = "h:mm" How bout adding the "AM|PM" to the time?

Clay Burch [Syncfusion]
Replied On June 10, 2002 11:49 AM UTC

Try the "t" format... CType(ts.GridColumnStyles(4), DataGridTextBoxColumn).Format = "t"


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon