Link to home
Start Free TrialLog in
Avatar of ISC
ISC

asked on

DataGrid Problem

Hi,

I am using a OracleDataAdapter to populate a DataTable.

The DataTable is then linked to DataGridView as a datasource.

The DataGridView is automaticallly populated with data and i have no control over the format of certain columns...

Example: there are date columns where the date is returned from the query in the form YYYYMMDD.

I would like to display date values in the gird as DD/MM/YYYY or MM/DD/YYYY depending on the users local date settting format....

*I have no control over the date format is returned back from the database...

Thnks Ian




ASKER CERTIFIED SOLUTION
Avatar of Craig Wagner
Craig Wagner
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops, didn't attach the first time.
DataGridViewColumns.jpg
Avatar of ISC
ISC

ASKER

Hi,

The following line does not return any format...

Call GetLocaleInfo(GetSystemDefaultLCID, LOCALE_SSHORTDATE, str, Len(str))

Ian
Avatar of ISC

ASKER

The code below just sets the contents of each cell to the format string which is not what I expected or want...

 Private Sub dgv_accrual_periods_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv_accrual_periods.CellFormatting

        If (e.ColumnIndex = 1) Or (e.ColumnIndex = 2) Or (e.ColumnIndex = 3) Then

            Dim l_objDateFormat As System.Globalization.DateTimeFormatInfo
            l_objDateFormat = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat
            e.CellStyle.Format = l_objDateFormat.ShortDatePattern.ToString

        End If

    End Sub
Avatar of ISC

ASKER

I also tried...

  Private Sub dgv_accrual_periods_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgv_accrual_periods.CellFormatting

        If (e.ColumnIndex = 1) Or (e.ColumnIndex = 2) Or (e.ColumnIndex = 3) Then

            Dim l_objDateFormat As System.Globalization.DateTimeFormatInfo
            l_objDateFormat = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat
            e.Value = String.Format(l_objDateFormat.ShortDatePattern.ToString, e.Value.ToString)

        End If

    End Sub