This is a migrated thread and some comments may be shown as answers.

Set value of new row column

2 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ramsha
Top achievements
Rank 1
Ramsha asked on 22 Feb 2016, 06:30 AM
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 Answers, 1 is accepted

Sort by
0
Accepted
Stefan Nenchev
Telerik team
answered on 22 Feb 2016, 11:12 AM
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
0
Ramsha
Top achievements
Rank 1
answered on 22 Feb 2016, 12:28 PM
Thanks! It works this way
Tags
GridView
Asked by
Ramsha
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Ramsha
Top achievements
Rank 1
Share this question
or