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

Cell value change event

7 Answers 1446 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ujjwal Lahoti
Top achievements
Rank 1
Ujjwal Lahoti asked on 28 Apr 2010, 05:58 PM
Hi, I am trying to add an event handler, that is called when a cell value is changed? After a quick look at the available Event handlers, I couldn't figure out which event handler I should choose. Any suggestions please?

7 Answers, 1 is accepted

Sort by
0
Tsvyatko
Telerik team
answered on 28 Apr 2010, 06:17 PM
Hi Ujjwal Lahoti,

Since the values in the cells represent properties from the data that grid is bound to, the most natural way to track such changes would be to subscribe to PropertyChanged/CollectionChanged events of your data. Thus  RadGridView does not expose such event.
However, it exposes events for editing, inserting,etc. for specific scenarios.

Please let me know if have any other questions or issues regarding this functionality.

All the best,
Tsvyatko
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
Ujjwal Lahoti
Top achievements
Rank 1
answered on 28 Apr 2010, 06:59 PM
Thanks for the reply.

Can you provide some sample code, that sets up an event handler, that is called, when the Grid is edited, and gives handle to the cell whose value is changed?
0
Tsvyatko
Telerik team
answered on 29 Apr 2010, 01:40 PM
Hello Ujjwal Lahoti,

I have created simple application with comments on the handlers regarding gridview editing mechanism. Please check it and let me know if you need any further assistance.

All the best,
Tsvyatko
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
Ujjwal Lahoti
Top achievements
Rank 1
answered on 07 May 2010, 10:28 PM
Thanks for the reply, the sample code doesn't completely answer my scenario. I need following things to make it work completely

1. How can I find out the cell being edited (Row and Column number)
2. I am using GridViewDataColumn, with CellTemplates. So in the CellValidated and CellEditEnded events, the cell value doesn't reflect the new changed value. Any suggestions how can this be done?
3. How can I programmatically set focus to a cell or put a specific cell in Edit mode. I need this, when the new value entered is not correct. Then I need to prevent user from leaving the Grid without entering the correct value or revert back to permissible value.

Sample Code from my Grid:
                <telerik:GridViewDataColumn Header="Modulation" Width="150" DataMemberBinding="{Binding Modulation, Mode=TwoWay}" TextAlignment="Center" >
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                            <TextBlock Text="{Binding Modulation}" Foreground="{Binding Path, Converter={StaticResource colorConverter}}"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                        <telerik:GridViewDataColumn.CellEditTemplate >
                            <DataTemplate>
                                <StackPanel Orientation="Horizontal">
                                <ComboBox Loaded="Editor_Loaded" Width="100" Margin="5, 0, 0, 0" Foreground="{Binding Path, Converter={StaticResource colorConverter}}" Text="{Binding Modulation, Mode=TwoWay}" Background="White"  SelectionChanged="modulationChanged">
                                        <ComboBoxItem>Static</ComboBoxItem>
                                        <ComboBoxItem>Rayleigh</ComboBoxItem>
                                        <ComboBoxItem>Rician</ComboBoxItem>
                                </ComboBox>
                                <Button Content="More..." Foreground="{Binding Path, Converter={StaticResource colorConverter}}"/>
                                </StackPanel>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>

                <!-- Fading Doppler -->
                <telerik:GridViewDataColumn Width="110" DataMemberBinding="{Binding fDFreq, Mode=TwoWay}" >
                    <telerik:GridViewDataColumn.Header>
                        <TextBlock Text="Fading Doppler (Hz)" TextAlignment="Center" TextWrapping="Wrap" />
                    </telerik:GridViewDataColumn.Header>
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding fDFreq}" Foreground="{Binding Path, Converter={StaticResource colorConverter}}" IsEnabled="{Binding Modulation, Converter={StaticResource isModulationOtherThanStatic}}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding fDFreq, Mode=TwoWay}" Foreground="{Binding Path, Converter={StaticResource colorConverter}}" IsEnabled="{Binding Modulation, Converter={StaticResource isModulationOtherThanStatic}}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>

0
Ujjwal Lahoti
Top achievements
Rank 1
answered on 10 May 2010, 07:36 PM
Any comments? I would really appreciate if you could answer my queries.


0
Tsvyatko
Telerik team
answered on 12 May 2010, 03:56 PM
Hi Ujjwal Lahoti,

Straight to your questions:
1. The cell that is being edited is the CurrentCell. You can get it directly from the RadGridView.CurrentCell property. In addition it has IsInEditMode, that can be in use.

2. Since Custom DataTemplate is used the cell.Value property will be null. In order to get the value of the current editor, you can go with getting the current cell content from the cell in CellValidating Event:
var dataElement = e.Cell.ChildrenOfType<ComboBox>().First();

3. You can set specific cell in edit mode by using the following code:
var row = SampleGrid.ItemContainerGenerator.ContainerFromIndex(0) as GridViewRow;
((GridViewCell)row.Cells[1]).BeginEdit();

Please, let me know if this works for you or if you have any further questions.

Kind regards,
Tsvyatko
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
Kha
Top achievements
Rank 1
answered on 11 Apr 2012, 09:27 AM
Hi Telerik team,

Are there any ways to get the event with only one click on CheckBox on RadGridView ?
With my situation, I would like to get the message to confirm when users check or uncheck  CheckBox  on RadGridView.
Please refer my code and the attached file for more detail.

<telerik:RadGridView.Columns>
                        <telerik:GridViewDataColumn Header="Group Name" DataMemberBinding="{Binding GroupName}" Width="130"  />
                        <telerik:GridViewDataColumn Header="Group Nice Name" DataMemberBinding="{Binding GroupNiceName}" />              
                        <telerik:GridViewDataColumn Header="Discontinued" DataMemberBinding="{Binding IsDiscontinued}" >
                            <telerik:GridViewDataColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding IsDiscontinued, Mode=TwoWay}" 
                                              IsEnabled="{Binding IsDiscontinued, Converter={StaticResource oppositeConverter}}"
                                              telerik:StyleManager.Theme="Office_Black">
                                    </CheckBox>
                                </DataTemplate>
                            </telerik:GridViewDataColumn.CellTemplate>
                        </telerik:GridViewDataColumn>                        
</telerik:RadGridView.Columns>
Tags
GridView
Asked by
Ujjwal Lahoti
Top achievements
Rank 1
Answers by
Tsvyatko
Telerik team
Ujjwal Lahoti
Top achievements
Rank 1
Kha
Top achievements
Rank 1
Share this question
or