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

CellEditTemplate Issue

1 Answer 66 Views
GridView
This is a migrated thread and some comments may be shown as answers.
JIG
Top achievements
Rank 1
JIG asked on 18 Feb 2019, 09:12 AM

I have a celledittemplate with a button inside that template, bound with command and command parameter.

When i enter the cell in edit mode it initializes the command but it is missing it's datacontext.
I found out that when i retrigger my command's RaiseCanExecuteChanged on the PreparedCellForEdit the datacontext is known.

So i was wondering if the datacontext is being set to late on the celledittemplate.
I would find it rather stupid to have to use the PreparedCellForEdit event everytime i need this behaviour

1 Answer, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 21 Feb 2019, 09:01 AM
Hello Jimmy,

Yes, you are right. The data context comes a bit after the initial data binding evaluation. Usually, this is okay because when the data context appears, the bindings re-evaluate and everything works properly. But when using commands you will need to raise the CanExecute handler manually when the cell is loaded. A possible approach for this would be to use the PreparedCellForEdit event as you are already doing. Or you can use a custom column that you can re-use across the different RadGridView instances you are using. You can raise the command in the PrepareCellForEdit() override of the column. I've attached a small example showing this approach. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
JIG
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Share this question
or