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.
Unfortunately, activation email could not send to your email. Please try again.

Format Date/Time Column in Datagrid

Thread ID:

Created:

Updated:

Platform:

Replies:

350 Jun 9,2002 03:35 AM Jun 10,2002 07:49 AM Windows Forms 3
loading
Tags: FAQ
Administrator [Syncfusion]
Asked On June 9, 2002 03:35 AM

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 08:27 AM

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
        DataGrid1.TableStyles.Add(ts)

        '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 01:50 AM

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 07:49 AM

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

CONFIRMATION

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.

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.

;