PDA

Click to See Complete Forum and Search --> : Datagrid Formatting


edna
Oct 16th, 2002, 04:15 PM
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.

DPritchard
Oct 17th, 2002, 12:04 PM
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.

Musician
Oct 17th, 2002, 06:53 PM
I do my best to avoid old vb functions and would use the tostring(formatstring) method instead.

DPritchard
Oct 17th, 2002, 06:55 PM
Busted :eek:

Listen to the Musician

Musician
Oct 17th, 2002, 07:08 PM
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 :)