formatting radgriddateView

4 posts, 1 answers
  1. mampus
    mampus avatar
    24 posts
    Member since:
    Oct 2010

    Posted 21 Oct 2010 Link to this post

    Hi there,
    is there any way to set the default year when the radgriddateview is load.??
    here my problem: i Have column call  "birthday"...i want to set the default year when loaded to 1980..
    how i do that..???
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 21 Oct 2010 Link to this post

    Hello Mampus,

    You could just set the NullValue when you are creating the column, like so:
    var dateTimeColumn = new GridViewDateTimeColumn("Date");
    dateTimeColumn.NullValue = new DateTime(2000, 1, 1);
    radGridView1.Columns.Add(dateTimeColumn);

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Abba
    Abba avatar
    22 posts
    Member since:
    Jan 2013

    Posted 28 Feb in reply to Emanuel Varga Link to this post

    I know this is older post.  But related to this, is there a way to do it when binding data from a datatable to the grid?

    Or is the way to loop thru the columns created and set NullValue

    Or is the way to set in cellFormatting if DbNull make value "SOMETHING"

     

    Thanks,

  5. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 29 Feb Link to this post

    Hi Abba,

    Thank you for writing.

    When the columns are autogenerated you only need to cast the column to the proper type in order to set the NullVallue:
    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        foreach (var item in radGridView1.Columns)
        {
            if (item is GridViewDateTimeColumn)
            {
                GridViewDateTimeColumn col = item as GridViewDateTimeColumn;
                col.NullValue = new DateTime(2000, 1, 1);
            }
        }
    }

    I hope this helps.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top