Results 1 to 5 of 5

Thread: Datagrid Formatting

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Posts
    14

    Datagrid Formatting

    Hi,

    Is there anyway to set the format value in property builder of a Datgrid control??

    I have a datgrid control which is bound to a dataset.
    For one of the field in the datagrid i want to set the format to be dd/mm/yy.
    There is a Data Formatting Expression option in Property Builder but i don't know to how to specify a value in that?

    Is there any other way to set this???
    for eg: i have a Date field which basically display date and time.Want to format this to dd/mm/yy when it shows the output in my Datagrid control.


    Thanks in advance.
    ami.

  2. #2
    Junior Member
    Join Date
    May 2002
    Posts
    20
    I usually use the ItemDatabound event of the datagird. Inside the event you could do something like this:
    NOTE: This is just scribble... you may have to double check it.

    'Let's say your date is in the 3rd cell from the left...

    If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
    Dim strDate = e.Item.Cells(2).Text
    e.Item.Cells(2).Text = format(strDate, "mm/dd/yy")
    End If

    Now, when the item becomes databound, this event will fire and the date will be reformatted.

    This may not be the best way... but it works well for me 9 times out of 10.

  3. #3
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I do my best to avoid old vb functions and would use the tostring(formatstring) method instead.

  4. #4
    Junior Member
    Join Date
    May 2002
    Posts
    20
    Busted

    Listen to the Musician

  5. #5
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Hehe I'm just being fussy. Now if somebody knew of a way of doing without vbcrlf I'd be rid of System.Microsoft.VisualBasic

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