Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > VB.NET 2002/2003 Basics
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 16th, 2004, 03:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Problem formatting date in Winform Datagrid

I cannot seem to get a date to appear the way I want in my datagrid. The value is in a SQL Server database and I want it to appear in "hh:mm:ss PM" format. SQL Server doesn't seem to offer that output option for their convert or cast function, so I'm trying to do it in VB. According to numerous sites, this code should work:

Dim dgtbcColumnStyle As DataGridTextBoxColumn
Dim dtTime As DataTable = grdHoursWorked.DataSource.Tables _("vw_TimeWorked")
Dim tsTime As DataGridTableStyle = New DataGridTableStyle()
tsTime.MappingName = dtTime.TableName

grdHoursWorked.TableStyles.Clear()

For Each dcColumn In dtTime.Columns
    dgtbcColumnStyle = New DataGridTextBoxColumn()

    Select Case dcColumn.ColumnName
        Case "Time In"
             With dgtbcColumnStyle
                  .TextBox.Enabled = False
                  .HeaderText = "Time In"
                  .MappingName = dcColumn.ColumnName
                  .Width = 320
                  .Alignment = HorizontalAlignment.Center
                  .Format = "hh:mm:ss tt"
....

I've traced it and know it's hitting the .FORMAT statement. No error is returned. I've checked the value after setting it and it does contain the format string. I know the ColumnStyle is being applied because the grid reflects the Width and Alignment settings. I've tried a variety of formats including those that have nothing to do with Date or Time and nothing seems to make a difference. No matter what I try, it consistently comes out:

1/1/1900 6:00:01 PM

when I just want:

6:00:01 PM (and NOT 13:00:01)

So what's the problem with the Format? Is there some magic setting I have to use to get it to recognize column formatting? Or is this just another case of .NET not working as advertised? I really don't care how I get there so long as the date is removed, so any suggestions are welcome.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Displaying multiline text in a datagrid (WinForm) markb1719 VB.NET 2 November 24th, 2008 09:52 PM
EXPORT DATAGRID TO EXCEL FORMATTING PROBLEM akshay144 VS.NET 2002/2003 2 October 31st, 2006 01:10 PM
How to wrap text in a winform Datagrid (vb.net) cliffd64 VB.NET 2002/2003 Basics 1 September 26th, 2006 03:10 PM
Date Formatting ozPATT Excel VBA 2 October 31st, 2005 12:03 PM
Add ComboBox into DataGrid(WinForm) shiju VS.NET 2002/2003 1 November 1st, 2003 11:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.