Results 1 to 3 of 3

Thread: Please Respond Urgent !!!!!!!!! HelpMe

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    10

    Unhappy Please Respond Urgent !!!!!!!!! HelpMe

    Hello all,

    We have a DataSet bound to a DataGrid, this DataSet has a datetime column, coming from SQL Server.

    We want to show this field on the DataGrid always as "DD/MM/YYYY", ignoring user's regional configuration.

    For example if the user has the date regional configuration as "DD*MM*YYYY" (with stars), the DataGridTextBoxColumn shows the date as "DD*MM*YYYY" even if our code is:

    DataGridTextBoxColumn oTextBoxNatural = new DataGridTextBoxColumn();
    oTextBoxNatural.MappingName = "datetime_field";
    oTextBoxNatural.HeaderText = "Show date as DD/MM/YYYY";
    oTextBox.Format = "dd/MM/yyyy";
    oTextBoxNatural.Width = 100;
    dty.GridColumnStyles.Add(oTextBoxNatural);

    How can we show the date always as "DD/MM/YYYY"? We do not want to depend on user's regional configuration since in our environment each user configurates this as they want.

    Thanks a lot.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Please Respond Urgent !!!!!!!!! HelpMe

    Please use descriptive thread titles, otherwise having titles at all is pointless. Help us help you. Also, this is a duplicate thread. Do not create duplicate threads as they simply clutter the forum and make it harder for people trying to help you and others trying to search for information. If you want to add information or bump your thread up the list simply add a new post to your existing thread. If noone has answered maybe noone knows. Try following the Windows Forms FAQ link in my signature. It has a wealth of information about using the DataGrid.

    I have never used styles on a DataGrid before but I just tried something similar and it worked fine. Have you made sure that you add the column styles to the table style before adding the table style to the grid?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Please Respond Urgent !!!!!!!!! HelpMe

    I'm using standard Australian date format, which is d/M/yyyy. Here's my code:
    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim dt As New DataTable
    3.  
    4.         dt.Columns.Add("Date", GetType(Date))
    5.  
    6.         For i As Integer = 1 To 10
    7.             Dim dr As DataRow = dt.NewRow()
    8.  
    9.             dr("Date") = Date.Today.AddDays(i)
    10.             dt.Rows.Add(dr)
    11.         Next
    12.  
    13.         Me.DataGrid1.DataSource = dt
    14.  
    15.         Dim dgtbc As New DataGridTextBoxColumn
    16.  
    17.         dgtbc.MappingName = "Date"
    18.         dgtbc.HeaderText = "Formatted Date"
    19.         dgtbc.Format = "yyyy/MM/dd"
    20.  
    21.         Dim dgts As New DataGridTableStyle
    22.  
    23.         dgts.GridColumnStyles.Add(dgtbc)
    24.         Me.DataGrid1.TableStyles.Add(dgts)
    25.     End Sub
    and here's the result:
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width