This question is locked. New answers and comments are not allowed.
Hi,
I have a dataGrid where each cell contains a custom object (that has a CanEdit property).
Now I have to disable/enable editing on cells depending on the CanEdit property of their content.
How can I do this?
(I see that you can disable editing on an entire column, but maybe there is a way to do this at row-level as well?)
Thanks,
Francesco
I have a dataGrid where each cell contains a custom object (that has a CanEdit property).
Now I have to disable/enable editing on cells depending on the CanEdit property of their content.
How can I do this?
(I see that you can disable editing on an entire column, but maybe there is a way to do this at row-level as well?)
Thanks,
Francesco
5 Answers, 1 is accepted
0
Hello frenk,
You can achieve this with custom cell edit template.
Here is an example:
and the code-behind:
Let us know if you need more help.
Kind regards,
Hristo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
You can achieve this with custom cell edit template.
Here is an example:
<UserControl x:Class="SilverlightApplication39.Page" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" |
Width="400" Height="300"> |
<Grid x:Name="LayoutRoot" Background="White"> |
<telerikGrid:RadGridView Grid.Row="1" Name="RadGridView1" CanUserReorderColumns="True" |
AutoGenerateColumns="False"> |
<telerikGrid:RadGridView.Columns> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Id}"> |
<telerikGrid:GridViewDataColumn.CellEditTemplate> |
<DataTemplate> |
<TextBox Text="{Binding Id}" IsEnabled="{Binding CanEdit}" /> |
</DataTemplate> |
</telerikGrid:GridViewDataColumn.CellEditTemplate> |
</telerikGrid:GridViewDataColumn> |
<telerikGrid:GridViewDataColumn DataMemberBinding="{Binding Name}"> |
<telerikGrid:GridViewDataColumn.CellEditTemplate> |
<DataTemplate> |
<TextBox Text="{Binding Name}" IsEnabled="{Binding CanEdit}" /> |
</DataTemplate> |
</telerikGrid:GridViewDataColumn.CellEditTemplate> |
</telerikGrid:GridViewDataColumn> |
</telerikGrid:RadGridView.Columns> |
</telerikGrid:RadGridView> |
</Grid> |
</UserControl> |
and the code-behind:
using System.Collections.ObjectModel; |
using System.Windows.Controls; |
namespace SilverlightApplication39 |
{ |
public partial class Page : UserControl |
{ |
public Page() |
{ |
InitializeComponent(); |
var myList = new ObservableCollection<Product>(); |
myList.Add(new Product() { Id = 1, Name = "Frame", CanEdit = true }); |
myList.Add(new Product() { Id = 2, Name = "Tire", CanEdit = false }); |
myList.Add(new Product() { Id = 3, Name = "Break", CanEdit = false }); |
RadGridView1.ItemsSource = myList; |
} |
} |
public class Product |
{ |
public int Id { get; set; } |
public string Name { get; set; } |
public bool CanEdit { get; set; } |
} |
} |
Let us know if you need more help.
Kind regards,
Hristo
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

BOARD LAB
Top achievements
Rank 1
answered on 14 May 2009, 03:08 PM
Worked perfectly.
Thanks!
Thanks!
0

BOARD LAB
Top achievements
Rank 1
answered on 18 May 2009, 03:23 PM
Hristo,
I have a show-stopper problem with this solution: editing events seems not to work correctly.
I set handlers on the grid for the Validating and EditEnded events and I expect them to be fired in this order:
- Validating -> e.NewValue is the new value, then I set e.IsValid to true;
- EditEnded
instead, what happens is the following:
- Validating is fired but e.NewValue still contains the old value. I cannot retrieve the edited value.
- EditEnded does not fire, regardless of my e.NewValue=true inside the Validating handler.
It works fine when I use regular text columns.
Am I missing something?
Thanks
Francesco
I have a show-stopper problem with this solution: editing events seems not to work correctly.
I set handlers on the grid for the Validating and EditEnded events and I expect them to be fired in this order:
- Validating -> e.NewValue is the new value, then I set e.IsValid to true;
- EditEnded
instead, what happens is the following:
- Validating is fired but e.NewValue still contains the old value. I cannot retrieve the edited value.
- EditEnded does not fire, regardless of my e.NewValue=true inside the Validating handler.
It works fine when I use regular text columns.
Am I missing something?
Thanks
Francesco
0
Hi frenk,
This is a known issue with the CellEditTemplate property. With the upcoming service pack you will be able to get the new value through GridViewCellValidatingEventArgs.EditingElement which represents the whole edit element (TextBox for example).
Sorry for the inconvenience caused.
P.S. Service pack will be available later today.
All the best,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
This is a known issue with the CellEditTemplate property. With the upcoming service pack you will be able to get the new value through GridViewCellValidatingEventArgs.EditingElement which represents the whole edit element (TextBox for example).
Sorry for the inconvenience caused.
P.S. Service pack will be available later today.
All the best,
Nedyalko Nikolov
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0

BOARD LAB
Top achievements
Rank 1
answered on 25 May 2009, 03:39 PM
Thanks, I'll try with the service pack.
I can live without the validating event but I really really need the EditEnded event to be fired.
I can live without the validating event but I really really need the EditEnded event to be fired.