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

CellEdit events are not firing in RadGridView after applying the custom CellTemplate

8 Answers 429 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rakesh
Top achievements
Rank 1
Rakesh asked on 04 Mar 2011, 08:38 AM
Hello,

 

I am using the RadGridView, and I need to subscribe to cell edit event of RADGrid. I get this event for every default cell however I am facing issue when I apply custom template to Combobox column. 

Details:
I have two columns, viz. GridViewDataColumn and GridViewComboBoxColumn. I am applying custom CellTemplate to GridViewComboBoxColumn  to have the default edit behaviour, but the grid cell edit event is not firing when I change the item in the combobox. I suspect this might be because I have overriden cell template. Event fires up without any issue if I use default GridViewComboBoxColumn without applying custom template.

Reason for using custom template: On default view, I want to display arrow on cell when it combo box column. Default behavior of GridViewComboBoxColumn does not display arrow, it shows arrow when you click on cell, then cell turns into combo box.

Please let me know how can I get cell edit event on custom template that I have applied on GridViewComboBoxColumn.



<TelerikGridView:RadGridView  x:Name="PersonData" 
                                      SelectedItem="{Binding Path=SelectedPersonItem, Mode=TwoWay}"   
                                      Width="Auto"  AutoGenerateColumns="False" 
                                      ItemsSource="{Binding Path=PersonCollection,Mode=TwoWay}"
                                      PreparingCellForEdit="CellDataChanged"
                                      >
                        <TelerikGridView:RadGridView.Columns>
                                <TelerikGridView:GridViewDataColumn DataMemberBinding="{Binding Path=Name, Mode=TwoWay}" Header="Sample Name" Width="*"/>
                               <TelerikGridView:GridViewComboBoxColumn Header="Department" Width="*"
                                                        ItemsSource="{Binding Path=Departments, Mode=TwoWay, Source={StaticResource PersonViewModel}}" 
                                                        DataMemberBinding="{Binding Path=DepartmentName, Mode=TwoWay}" 
                                                        >
                    <TelerikGridView:GridViewComboBoxColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <telerik:RadComboBox
                                    Name="displayCombo12"  
                                    ItemsSource="{Binding Path=Departments, Mode=TwoWay, Source={StaticResource PersonViewModel}}"  
                                    SelectedValue="{Binding DepartmentName, Mode=TwoWay}" >
                                </telerik:RadComboBox>
                            </StackPanel>
                        </DataTemplate>
                    </TelerikGridView:GridViewComboBoxColumn.CellTemplate>
                </TelerikGridView:GridViewComboBoxColumn>
                
            </TelerikGridView:RadGridView.Columns>
        </TelerikGridView:RadGridView>


Thanks,
Rakesh K

8 Answers, 1 is accepted

Sort by
0
Yavor Georgiev
Telerik team
answered on 06 Mar 2011, 01:31 AM
Hello Rakesh,

 As you have correctly guessed, using a custom CellTemplate that contains an object that handles user input (in this case RadComboBox) will circumvent the normal RadGridView editing mechanism for that column.

 What you can do is try and handle the Click event of the RadComboBox in your template and in the event handle manually initiate edit mode of the RadGridView for the cell that contains the RadComboBox that raised the event.

Regards,
Yavor Georgiev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Frédéric
Top achievements
Rank 1
answered on 19 Apr 2011, 07:53 PM
Hello Yavor,

The DataGrid in the silverlight sdk correctly propagate the cell events, like the PrepareCellForEditEvent, with combobox in the cell template. 

It should be possible for the GridView to behave like this.

I think this should be logged as a bug.

Thanks.
0
Yavor Georgiev
Telerik team
answered on 19 Apr 2011, 08:06 PM
Hi Frédéric,

 If you define a CellTemplate, the contents of the template will be available when not in edit mode - that is to say, if you define a combo box in the CellTemplate of a column, interacting with the combo won't cause the GridView to enter edit mode, so the CellEditEnded event won't fire.

 However, if you define a combo box in a column's CellEditTemplate, the template's contents will be available in edit mode, so when you interact with the combo, you are already in edit mode. In this case, the CellEditEnded event will fire as expected.

Best wishes,
Yavor Georgiev
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Frédéric
Top achievements
Rank 1
answered on 20 Apr 2011, 02:21 PM
Hi Yavor,

My mistake, I understand that it is the correct behavior for the CellTemplate.

But I wanted to say is that when you have a ComboBox in the CellEditTemplate, the PrepareCellForEditEvent is not trigered when the cell switch to edit mode.

I have migrated a Silverlight DataGrid to RadGridView and I lost that fonctionnality in the process.

Frédéric


0
Roman
Top achievements
Rank 1
answered on 10 Dec 2018, 03:53 PM
I'm having a pretty similar problem, but in my case it is not a ComboBoxColumn but a GridViewMaskedInputColumn with a control inside created by me. I tried to apply your solution and, when my control got focus, I try to start edition with BeginEdit() method of GridView. However, given that when I click on my control then no row is still selected (or maybe another one is the selected one), then the edition is not working or worst, the edition starts for another item. How can I access the row that contains the element that got focus?
0
Dilyan Traykov
Telerik team
answered on 13 Dec 2018, 12:57 PM
Hello Roman,

Generally speaking, you can handle the control's GotFocus event and get ahold of the parent row via the ParentOfType extension method. You can then edit the underlying item using the approach suggested in this article.

private void Element_GotFocus(object sender, RoutedEventArgs e)
{
    var control = sender as Control;
    var row = control.ParentOfType<GridViewRow>();
    var item = row.DataContext;
    row.GridViewDataControl.Items.EditItem(item);
    // edit item
    row.GridViewDataControl.Items.CommitEdit();
}

Please let me know whether such an approach would work for you. If that is not the case, please specify how exactly you've set up your column so that I can better understand your scenario and assist you?

I look forward to your reply.

Regards,
Dilyan Traykov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Roman
Top achievements
Rank 1
answered on 14 Dec 2018, 07:30 AM

Hi Dilyan,

Finally, I was able to solve my problem by defining just the CellEditTemplate (so, this way, I actually enter into the edit mode and exit from it when the edition is complete), and in order to solve the problem of visualizing it as I want (in this case, a control that converted a double into a coordinates string) in read mode, I used a Converter instead of overwriting the CellTemplate, this way:
<telerik:GridViewDataColumn
        Header="LAT"
        MinWidth="85"
        ShowDistinctFilters="False"
        ShowFilterButton="False"
        IsFilterable="False"
        IsSortable="False"
        DataMemberBinding="{Binding Latitude, Converter={StaticResource LatitudeCoordinatesConverter}}">
        <telerik:GridViewColumn.CellEditTemplate>
            <DataTemplate>
                <coordinateTextBox:CoordinateTextBox
                    Width="auto" 
                    Height="auto" 
                    CoordinatePosition="Latitude"
                    Value="{Binding Latitude, Mode=TwoWay}" 
                    Style="{DynamicResource CoordinatesTransparentStyle}"/>
            </DataTemplate>
        </telerik:GridViewColumn.CellEditTemplate>
</telerik:GridViewDataColumn>

This way, I am able to edit the row correctly and visualize it the way I want.
Kind regards ,
Román

0
Dilyan Traykov
Telerik team
answered on 14 Dec 2018, 11:39 AM
Hi Román,

I'm happy to hear that you've found a suitable solution to your requirement. Thank you for sharing it with the community as well.

If I can further assist you in any way, please let me know.

Regards,
Dilyan Traykov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Rakesh
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Frédéric
Top achievements
Rank 1
Roman
Top achievements
Rank 1
Dilyan Traykov
Telerik team
Share this question
or