spebola Posted June 11, 2003 Posted June 11, 2003 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? Quote
hbash54 Posted June 17, 2003 Posted June 17, 2003 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. Quote
spebola Posted June 17, 2003 Author Posted June 17, 2003 Thanks for the ideas. I am leaning towards (iii). Quote
*Experts* Bucky Posted June 17, 2003 *Experts* Posted June 17, 2003 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 Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.