Hi,
I am using RadGridview which Itemsource is Observablecollection<CustomObject>
While editing particular cell, i want to change the another cell's content which is read only.
For Example:
Public class CustomObject
{
public string Identifier{get;set;}
public string DisplayName{get;set;}
}
My requirement is when i change the Identifier, need to change the "DisplayName" value.
I tried to change the "DisplayName" value in both CellValidated and CellValidating event. But not able to see the updated value in the UI.
I tried grid.Rebind() in both CellValidated and CellValidating event, the current cell (i.e Identifier) modification is getting lost and the updated DisplayName value is shown in the UI.
How to modify the other column value based on some cell value changes and refresh the GridView?
code snippets:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
grid.CellValidated -= new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
grid.CellValidated += new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
grid.ItemsSource = GetObservableList();
}
void grid_CellValidated(object sender, Telerik.Windows.Controls.GridViewCellValidatedEventArgs e)
{
Telerik.Windows.Controls.RadGridView g = e.Cell.DataColumn.Parent as Telerik.Windows.Controls.RadGridView;
//Modify the DisplayName cell value.
var currentObj = e.Cell.DataContext as CustomObject;
currentObj.DisplayName = "Test";
var list = g.ItemsSource as ObservableCollection<CustomObject>;
CustomObject p = list.Where(obj => obj.UniqueKey == currentObj.UniqueKey).FirstOrDefault();
p = currentObj;
p.DisplayName = "Test";
}
private static ObservableCollection<CustomObject> GetObservableList()
{
ObservableCollection<CustomObject> table = new ObservableCollection<CustomObject>();
for (int i = 0; i <= 3; i++)
{
CustomObject p = new CustomObject();
p.UniqueKey = "aa" + i;
p.Identifier = "des" + i;
p.DisplayName = "arfea" + i;
table.Add(p);
}
return table;
}
public class CustomObject
{
public CustomObject() { }
private string _key = null;
private string _identifier = null;
private string _displayName = null;
public string UniqueKey { get { return _key; } set { _key = value; } }
public string Identifier {get { return this._identifier; } set { this._identifier = value;}}
public string DisplayName { get { return this._displayName; } set { this._displayName = value; } }
}
}
XMAL:
<Grid>
<telerik:RadGridView x:Name="grid" x:FieldModifier="public" AutoGenerateColumns="False" ItemsSource="{Binding}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding UniqueKey}" Header="UniqueKey" UniqueName="UniqueKey" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Identifier, Mode=TwoWay}" UniqueName="Identifier" Header="Identifier" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding DisplayName, Mode=OneWay}" UniqueName="DisplayName" Header="DisplayName" IsReadOnly="True" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
Thanks,
Thanga
I am using RadGridview which Itemsource is Observablecollection<CustomObject>
While editing particular cell, i want to change the another cell's content which is read only.
For Example:
Public class CustomObject
{
public string Identifier{get;set;}
public string DisplayName{get;set;}
}
My requirement is when i change the Identifier, need to change the "DisplayName" value.
I tried to change the "DisplayName" value in both CellValidated and CellValidating event. But not able to see the updated value in the UI.
I tried grid.Rebind() in both CellValidated and CellValidating event, the current cell (i.e Identifier) modification is getting lost and the updated DisplayName value is shown in the UI.
How to modify the other column value based on some cell value changes and refresh the GridView?
code snippets:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
grid.CellValidated -= new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
grid.CellValidated += new EventHandler<Telerik.Windows.Controls.GridViewCellValidatedEventArgs>(grid_CellValidated);
grid.ItemsSource = GetObservableList();
}
void grid_CellValidated(object sender, Telerik.Windows.Controls.GridViewCellValidatedEventArgs e)
{
Telerik.Windows.Controls.RadGridView g = e.Cell.DataColumn.Parent as Telerik.Windows.Controls.RadGridView;
//Modify the DisplayName cell value.
var currentObj = e.Cell.DataContext as CustomObject;
currentObj.DisplayName = "Test";
var list = g.ItemsSource as ObservableCollection<CustomObject>;
CustomObject p = list.Where(obj => obj.UniqueKey == currentObj.UniqueKey).FirstOrDefault();
p = currentObj;
p.DisplayName = "Test";
}
private static ObservableCollection<CustomObject> GetObservableList()
{
ObservableCollection<CustomObject> table = new ObservableCollection<CustomObject>();
for (int i = 0; i <= 3; i++)
{
CustomObject p = new CustomObject();
p.UniqueKey = "aa" + i;
p.Identifier = "des" + i;
p.DisplayName = "arfea" + i;
table.Add(p);
}
return table;
}
public class CustomObject
{
public CustomObject() { }
private string _key = null;
private string _identifier = null;
private string _displayName = null;
public string UniqueKey { get { return _key; } set { _key = value; } }
public string Identifier {get { return this._identifier; } set { this._identifier = value;}}
public string DisplayName { get { return this._displayName; } set { this._displayName = value; } }
}
}
XMAL:
<Grid>
<telerik:RadGridView x:Name="grid" x:FieldModifier="public" AutoGenerateColumns="False" ItemsSource="{Binding}">
<telerik:RadGridView.Columns>
<telerik:GridViewDataColumn DataMemberBinding="{Binding UniqueKey}" Header="UniqueKey" UniqueName="UniqueKey" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding Identifier, Mode=TwoWay}" UniqueName="Identifier" Header="Identifier" />
<telerik:GridViewDataColumn DataMemberBinding="{Binding DisplayName, Mode=OneWay}" UniqueName="DisplayName" Header="DisplayName" IsReadOnly="True" />
</telerik:RadGridView.Columns>
</telerik:RadGridView>
</Grid>
Thanks,
Thanga