Hello,
I have a RadGridView that will be populated by a dynamically generated DataTable. I have therefore set the RadGridView property as follows: AutoGenerateColumns="True". My DataTable will contain dates, strings and integers. I want to be able to use a DataTemplate for each data type in the automatically generated columns of the grid. For instance, for string columns, I will want to use a TextBox with text wrapping, which accepts returns and has a certain maximum width.
For the purpose of this question, my datatable will be created and bound to the RadGridView as follows:
And my RadGridView currently looks like:
Can you help me specify the binding of the text property of the DataTemplate that uses a TextBox? It should be a two-way binding with the underlying cell in the DataTable. Could you provide me with a basic working example of what I am trying to achieve? This would be greatly appreciated.
Thanks!
I have a RadGridView that will be populated by a dynamically generated DataTable. I have therefore set the RadGridView property as follows: AutoGenerateColumns="True". My DataTable will contain dates, strings and integers. I want to be able to use a DataTemplate for each data type in the automatically generated columns of the grid. For instance, for string columns, I will want to use a TextBox with text wrapping, which accepts returns and has a certain maximum width.
For the purpose of this question, my datatable will be created and bound to the RadGridView as follows:
DataTable table = new DataTable();
table.Columns.Add(new DataColumn("Date Column 1", typeof(DateTime)));
table.Columns.Add(new DataColumn("Date Column 2", typeof(DateTime)));
table.Columns.Add(new DataColumn("String Column 1", typeof(string)));
table.Columns.Add(new DataColumn("String Column 2", typeof(string)));
DataRow row1 = table.NewRow();
row1[table.Columns[0]] = DateTime.Now;
row1[table.Columns[1]] = DateTime.Now.AddDays(10);
row1[table.Columns[2]] = "some string";
row1[table.Columns[3]] = "some other string";
table.Rows.Add(row1);
radGridView1.ItemsSource = table;And my RadGridView currently looks like:
<telerik:RadGridView HorizontalAlignment="Stretch" Name="radGridView1" VerticalAlignment="Stretch" AutoGenerateColumns="True">
<telerik:RadGridView.Resources>
<DataTemplate x:Key="TextCellEditorTemplate">
<TextBox Background="LightYellow" MaxWidth="250" TextWrapping="Wrap" AcceptsReturn="True"
Text="{Binding WHAT_GOES_HERE?}" />
</DataTemplate>
<DataTemplate x:Key="DateTimeCellEditorTemplate">
...
</DataTemplate>
<DataTemplate x:Key="IntegerCellEditorTemplate">
...
</DataTemplate>
</telerik:RadGridView.Resources>
</telerik:RadGridView>Can you help me specify the binding of the text property of the DataTemplate that uses a TextBox? It should be a two-way binding with the underlying cell in the DataTable. Could you provide me with a basic working example of what I am trying to achieve? This would be greatly appreciated.
Thanks!
