Set value of new row column

3 posts, 1 answers
  1. Ramsha
    Ramsha avatar
    4 posts
    Member since:
    Feb 2016

    Posted 22 Feb Link to this post

    Hi, I want to set DateTime value for my radGridview's DataColumn. I tried doing it in the AddingNewDataItem event of the Grid but getting error:

    Cannot implicitly convert type 'System.DateTime' to 'Telerik.Windows.Controls.GridViewDataColumn

    This is the AddingNewDataItem event handler:

    private void grdProductGrid_AddingNewDataItem_1(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
     {
                e.NewObject =new Product();
                Date = System.DateTime.Today;
     }

    Date is the name of my column.

     
  2. Answer
    Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    277 posts

    Posted 22 Feb Link to this post

    Hi Ramsha,

    You need to set the Date with the initialization of the new object. So if your product has the following properties - string Name, DateTime Date, int ID - you can use the following approach:

    private void grdProductGrid_AddingNewDataItem(object sender, Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs e)
            {
                e.NewObject = new Product () { Name = "SomeName", Date= new DateTime(1990, 01, 31), ID = 55};
            }

    I have also added a sample project that implements the desired behavior. Please, review it and update me if it was useful. Of course, if you have any further questions or concerns, do not hesitate to contact us.

    Regards,
    Stefan Nenchev
    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
  3. DevCraft banner
  4. Ramsha
    Ramsha avatar
    4 posts
    Member since:
    Feb 2016

    Posted 22 Feb in reply to Stefan Nenchev Link to this post

    Thanks! It works this way
Back to Top