Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Culture-Independent Date formatting required in DataColumn
 

Culture-Independent Date formatting required in DataColumn

Hi All,

Keeping in view that culture-independent formatting is required I want to facilitate the application user to enter date in dd/MM/yy format in a column of DataGridView having DateTime type.

Following is my sample code for the said purpose.

        Dim dgv As New DataGridView()
        Me.Controls.Add(dgv)

        Dim dt As New DataTable()
        dt.Locale = System.Globalization.CultureInfo.InvariantCulture 'New System.Globalization.CultureInfo("en-gb")

        Dim dc0 As New DataColumn("Name", System.Type.GetType("System.String"))
        Dim dc1 As New DataColumn("DOB", System.Type.GetType("System.DateTime"))
        dt.Columns.Add(dc0)
        dt.Columns.Add(dc1)
        Dim dr As DataRow = dt.NewRow()

        dgv.DataSource = dt

        dgv.Dock = DockStyle.Fill
        dgv.Columns("Name").AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill

        dgv.Columns("DOB").DefaultCellStyle.Format = "dd/MM/yy"

        dgv.Show()


Although I am able to format the column to the desired date format but it still forces user to enter the date in MM/dd/yy format as the regional setting in control panel is set to MM/dd/yy format.

Is there any way to achieve this without changing the local regional setting on the target system?

I have also tried dt.Locale property but of no use.

Regards,

_______
Ali

Share your knowledge. It's a way to achieve immortality. - Dalai Lama MSN: kalilani@hotmail.com - Yahoo: kalilanipk
Ali .NET  Monday, August 10, 2009 1:37 PM
Have you tried My.Application.ChangeCulture to adjust this for your app? I think this is whatDataGridView pays attention to. Do this early when your app starts up, I'd recommend.
  • Marked As Answer byAli .NET Tuesday, August 11, 2009 3:53 AM
  •  
BinaryCoder  Monday, August 10, 2009 11:29 PM
Have you tried My.Application.ChangeCulture to adjust this for your app? I think this is whatDataGridView pays attention to. Do this early when your app starts up, I'd recommend.
  • Marked As Answer byAli .NET Tuesday, August 11, 2009 3:53 AM
  •  
BinaryCoder  Monday, August 10, 2009 11:29 PM
Yes. that worked.

Thank you very much BinaryCoder.
Share your knowledge. It's a way to achieve immortality. - Dalai Lama MSN: kalilani@hotmail.com - Yahoo: kalilanipk
Ali .NET  Tuesday, August 11, 2009 3:55 AM

You can use google to search for other answers

Custom Search

More Threads

• Sorting databound ComboBox
• TextBox binding and format
• Get dgv cell style back
• Datagridview Celltype: set at runtime; How set of hosted custom control in property grid
• deisgner not creating insertcommand
• binding an object,pointing to another object, to a datagridview
• Problem in databinding SelectedValue of comboxbox to another DataSet object
• Error in ErrorProvider?
• How to find Start Byte and EndByte
• How to disable DataGridView to sort?