This question is locked. New answers and comments are not allowed.
Hi,
I need to generate a grid dynamically, and add a CellEditorTemplate based on the type of data.
I'm currently doing this on Xaml:
<UserControl.Resources>
<res:Resource x:Key="ResourcesList"/>
<DataTemplate x:Key="intEdit">
<Grid>
<telerikInput:RadNumericUpDown Maximum="1000000" Value="{Binding}"></telerikInput:RadNumericUpDown>
</Grid>
</DataTemplate>
<DataTemplate x:Key="stringEdit">
<Grid>
<TextBox Text="{Binding}"></TextBox>
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<telerikGrid:RadGridView x:Name="tableEditorGrid" AutoGenerateColumns="False" Height="300"></telerikGrid:RadGridView>
</Grid>
And in codebehind doing something like this:
GridViewDataColumn colName = new GridViewDataColumn();
colName.HeaderText = property.Name;
Binding bd = new Binding(property.Name);
bd.Mode =BindingMode.TwoWay;
colName.DataMemberBinding = bd;
tableEditorGrid.Columns.Add(colName);
if (property.ScalarType.NativeType.Contains("Int"))
{
colName.CellEditTemplate = this.Resources["intEdit"] as DataTemplate;
}
else
{
colName.CellEditTemplate = this.Resources["stringEdit"] as DataTemplate;
}
What it happens is that the property doesen't get bind to the data template, and to work I need to explicity define the binding in the datatemplate:(
Suppose that property.Name is something like "Phone" then in order for this to work i need explicity define like this
<DataTemplate x:Key="stringEdit">
<Grid>
<TextBox Text="{Binding Phone, Mode=TwoWay}"></TextBox>
</Grid>
</Border>
</DataTemplate>
But I want that the data template for the CellEditTemplate to get automaticaly binded to the GridViewDataColumn DataMemberBinding.Is this possible?
I'm sorry if this turn out be confusing but I couldn't find any other way to expose my problem.
Thanks,
Ivo
I need to generate a grid dynamically, and add a CellEditorTemplate based on the type of data.
I'm currently doing this on Xaml:
<UserControl.Resources>
<res:Resource x:Key="ResourcesList"/>
<DataTemplate x:Key="intEdit">
<Grid>
<telerikInput:RadNumericUpDown Maximum="1000000" Value="{Binding}"></telerikInput:RadNumericUpDown>
</Grid>
</DataTemplate>
<DataTemplate x:Key="stringEdit">
<Grid>
<TextBox Text="{Binding}"></TextBox>
</Grid>
</Border>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<telerikGrid:RadGridView x:Name="tableEditorGrid" AutoGenerateColumns="False" Height="300"></telerikGrid:RadGridView>
</Grid>
And in codebehind doing something like this:
GridViewDataColumn colName = new GridViewDataColumn();
colName.HeaderText = property.Name;
Binding bd = new Binding(property.Name);
bd.Mode =BindingMode.TwoWay;
colName.DataMemberBinding = bd;
tableEditorGrid.Columns.Add(colName);
if (property.ScalarType.NativeType.Contains("Int"))
{
colName.CellEditTemplate = this.Resources["intEdit"] as DataTemplate;
}
else
{
colName.CellEditTemplate = this.Resources["stringEdit"] as DataTemplate;
}
What it happens is that the property doesen't get bind to the data template, and to work I need to explicity define the binding in the datatemplate:(
Suppose that property.Name is something like "Phone" then in order for this to work i need explicity define like this
<DataTemplate x:Key="stringEdit">
<Grid>
<TextBox Text="{Binding Phone, Mode=TwoWay}"></TextBox>
</Grid>
</Border>
</DataTemplate>
But I want that the data template for the CellEditTemplate to get automaticaly binded to the GridViewDataColumn DataMemberBinding.Is this possible?
I'm sorry if this turn out be confusing but I couldn't find any other way to expose my problem.
Thanks,
Ivo