Results 1 to 4 of 4

Thread: Time in datagrid

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    Time in datagrid

    Hi all ive got a datagrid which is returning 3 column on a rs

    ID, Time, Task

    time is being shown as 01/01/1900 i guess this is because i am only storing a time and no date (Idont want to store a date) how can i apply the mm/hh/ss format to this in the datagrid I am running a function to format the DG so that may help

    VB Code:
    1. Private Sub AddCustomDataTableStyles(ByVal dstData As DataSet)
    2.  
    3.         'Clear the table styles for the datagrid
    4.         DataGrid1.TableStyles.Clear()
    5.  
    6.         'Declare local variables
    7.         Dim tsTableStyle As New DataGridTableStyle
    8.         Dim tcTextCol As DataGridTextBoxColumn
    9.         Dim intCounter As Integer
    10.  
    11.         'Map the table style to the table in the dataset
    12.         tsTableStyle.MappingName = dstData.Tables(0).TableName()
    13.  
    14.         'Add textbox column style for each column in the dataset
    15.         For intCounter = 0 To dstData.Tables(0).Columns.Count() - 1
    16.  
    17.             'Reinstantiate the text box column and set mappings and attributes
    18.             tcTextCol = New DataGridTextBoxColumn
    19.             tcTextCol.MappingName = dstData.Tables(0).Columns.Item(intCounter).ColumnName
    20.             tcTextCol.HeaderText = dstData.Tables(0).Columns.Item(intCounter).ColumnName
    21.  
    22.             'Set column size based on name
    23.             Select Case tcTextCol.MappingName()
    24.                 Case "Task"
    25.                     tcTextCol.Width() = 275
    26.                 Case "Time"
    27.                     tcTextCol.Width() = 51
    28.                 Case "ID"
    29.                     tcTextCol.Width() = 18
    30.                 Case Else
    31.                     tcTextCol.Width() = 50
    32.             End Select
    33.  
    34.             'Add the column to the table style
    35.             tsTableStyle.GridColumnStyles.Add(tcTextCol)
    36.         Next
    37.  
    38.         'Add the table styles to the datagrid
    39.         DataGrid1.TableStyles.Add(tsTableStyle)
    40.     End Sub
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Addicted Member
    Join Date
    Aug 2002
    Location
    top of the mountain
    Posts
    234
    'Set column size based on name
    Select Case tcTextCol.MappingName()
    Case "Task"
    tcTextCol.Width() = 275
    Case "Time"
    tcTextCol.Width() = 51
    Case "ID"
    tcTextCol.Width() = 18
    Case Else
    tcTextCol.Width() = 50
    End Select
    You can add: in section : Case "Time"
    tcTextCol.Format = "MM/dd/yyyy"

    or any format you want

    regard j

  3. #3

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539
    thats cool thanks mate

    Do u know if theres a way of changing the value of the column ?
    i mean some records return 00:01 because there an all day event i would like to If possible on records with 00:01 to change to "All Day"
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  4. #4
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    ah the only way you are going to do thatt, is to load the intial value as an unformatted string and then run through the dataset and set the format accordingly to whether a time format or the 'All Day' text. Table styles wont help you there and even that won't work because the underlying value is a date/time stamp field. Perhpas your best bet is to use an unbound field which gets populated on the basis of the value of the underlying dataset.

    Sorry can't think of an easy answer, maybe someonelse has one

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width