1

It seems that the DateGridView1 is possible to change format of the date in specific column and I am using XtraGridView from DevExpress, May I ask that is it possible to change the date format in specific column in XtraGridView, I already coded but it won't work for me.

This is my code

Private Sub GridViewOBTA_ColumnChanged(sender As Object, e As EventArgs) Handles GridViewOBTA.ColumnChanged
        GridViewOBTA.Columns(4).DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
        GridViewOBTA.Columns(4).DisplayFormat.FormatString = "d"
    End Sub

I want to display the months and years only in GridViewOBTA. The date is in the 5th column. I put Column(4) because it started in 0, if I'm not mistaken. And I put formatString = "d" for the short date.

Thank you for answering this question.

Sincerely, Mr. Dev

  • The formatting can be done direct from the designer, or at runtime. Have a look at this [support desk call](https://supportcenter.devexpress.com/ticket/details/t963270/gridview-how-to-set-the-format-string-of-the-date-columns) – Julian Mar 23 '23 at 09:37

1 Answers1

0

The below works for me

 GridViewOBTA.Columns("columname").DisplayFormat.FormatType = DevExpress.Utils.FormatType.DateTime
 GridViewOBTA.Columns("columname").DisplayFormat.FormatString = "dd/MM/yyyy HH:mm:ss"

You can change "dd/MM/yyyy HH:mm:ss" to "MM/yyyy" for months and year only.

Also i use this code when i fill the gridview and not within an event.(This is the issue in your case i think)

S3minaki
  • 297
  • 3
  • 19
  • Wow it works, thank you so much @S3minaki and how about the date is in word? for example: 01/2023 it displayed = January 2023 in the GridViewOBTA? It is still possible? – DeveloperGuy Mar 23 '23 at 09:41
  • "MMMM/yyyy" for full month month display "MMM/yyyy" for short month display – S3minaki Mar 23 '23 at 09:44
  • Your a life saver, thank you so much. – DeveloperGuy Mar 23 '23 at 09:46
  • I suggest you to do this in order to find your desired view. create a test "DateEdit" control, and from the arrow on the upper right corner of the control select "change Mask", then scroll down on the list and select "Create New Mask...". There you can find all the details that can help you! – S3minaki Mar 23 '23 at 09:48
  • There are many date formats you can use. DevExpress provide a helper. You can also find it on the Microsoft site here https://learn.microsoft.com/en-us/system-center/orchestrator/standard-activities/format-date-time?view=sc-orch-2022 – Julian Mar 23 '23 at 09:49
  • Yes I already Applied in the DateEdit but I didn't find a settings for the XtraGridView, So I've decided to code it. And you helped me also. Thank you so much,.. – DeveloperGuy Mar 23 '23 at 09:50