Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am using a datagrid with one of the columns containing a date.

I would like this column to only contain the day of the month.

 

Day Price

2 30.00

6 32.00

 

instead of

 

01/02/2003 30.00

01/06/2003 32.00

 

This is the code I am using:

 

dgPrEntry.TableStyles.Clear()

dgPrEntry.DataSource = ds.Tables(0)

Dim ts1 As New DataGridTableStyle

ts1.MappingName = ds.Tables(0).ToString

Dim TC0 As New DataGridTextBoxColumn

TC0.MappingName = "PR_EffDate"

TC0.HeaderText = "Day"

TC0.Width = 80

ts1.GridColumnStyles.Add(TC0)

 

Any suggestions?

Posted

Three options come to mind:

 

(i) Perhaps there is a .Format value usable here. You should find a complete description of this property.

 

(ii) You can subclass a DataTextColumn and override it's paint method.

 

(iii) Make the field as a calculated field in your database.

  • *Experts*
Posted

Another option is to, before binding the DataTable to the DataGrid,

is to loop through all the rows and modify the Day column to only

include the date. You can convert the date to a DateTime variable

by using DateTime.Parse(). The day of month is in

its Day property, then just set this back to the column.

 

Dim dr As DataRow

For Each dr in ds.Tables(0) ' Loop through each row  
 Dim theDate As DateTime = DateTime.Parse(dr.Item(0).ToString()) ' Assuming 0 is the Day column, set it to a DT variable
 dr.Item(0) = theDate.Day ' Set the day of month as the new value
Next

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...