Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Customize Date format in XtraGridView in vb.net

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Thank you for answering this question.

Sincerely,
Mr. Dev

>Solution :

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading