I am using a WPF Telerik Gridview control and one of the columns is a GridviewCombobox
Is it possible to have it so that each row in the data grid can have a Combobox with its own data source values?
E.g. Row 1 will have a combo box containing list of Countries and Row 2 will have a combobox containing list of Continents?
Not related in any way.
Thanks.
4 Answers, 1 is accepted
You may set the ItemsSourceBinding of the column. For a sample project illustrating the implementation, please refer to this forum thread. You may take a look at this blog post as well.
Maya
the Telerik team
Thanks for the response.
I tried to set the ItemsSourceBinding for the combo box but it didnt quite work.
This is the sample code:
<telerik:RadGridView HorizontalAlignment="Left" Margin="12,24,0,0" Name="radGridView1" VerticalAlignment="Top" Width="387" ItemsSource="{Binding DatabaseParams}" AutoGenerateColumns="False" Height="201" ShowGroupPanel="False" RowIndicatorVisibility="Collapsed" > <telerik:RadGridView.RowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="MinHeight" Value="40"></Setter> </Style> </telerik:RadGridView.RowStyle> <telerik:RadGridView.AlternateRowStyle> <Style TargetType="telerik:GridViewRow"> <Setter Property="MinHeight" Value="40"></Setter> <Setter Property="Background" Value="AliceBlue"></Setter> </Style> </telerik:RadGridView.AlternateRowStyle> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Param Name" DataMemberBinding="{Binding Name}" Width="150" /> <telerik:GridViewComboBoxColumn Header="Param Value" DataMemberBinding="{Binding Value}" ItemsSourceBinding="{Binding ParamValues}" UniqueName="ParamValue" SelectedValueMemberPath="Value" DisplayMemberPath="Description" Width="230" /> </telerik:RadGridView.Columns></telerik:RadGridView> public class DatabaseParamValue { public string Description { get; set; } public string Value { get; set; } public DatabaseParamValue(string description, string value) { Description = description; Value = value; } } public class DatabaseParam { public string Name { get; set; } public string Value { get; set; } public List<DatabaseParamValue> ParamValues; }}List<DatabaseParam> DatabaseParams = new List<DatabaseParam>();DatabaseParam param = new DatabaseParam();param.Name = "Row-1";param.Value = "2";param.ParamValues = new List<DatabaseParamValue>();param.ParamValues.Add(new DatabaseParamValue("Name-1", "1"));param.ParamValues.Add(new DatabaseParamValue("Name-2", "2"));param.ParamValues.Add(new DatabaseParamValue("Name-3", "3"));DatabaseParams.Add(param);DatabaseParam param2 = new DatabaseParam();param2.Name = "Row-2";param2.Value = "12";param2.ParamValues = new List<DatabaseParamValue>();param2.ParamValues.Add(new DatabaseParamValue("Name-21", "11"));param2.ParamValues.Add(new DatabaseParamValue("Name-22", "12"));param2.ParamValues.Add(new DatabaseParamValue("Name-23", "13"));DatabaseParams.Add(param2);radGridView1.ItemsSource = DatabaseParams;radGridView1.Rebind();Regards
Apoorva
As illustrated in the blog post and the sample project in the forum thread, you need to expose a new property in the business object of the RadGridView. I believe in your case it is DatabaseParam. So, you in the class definition, you may declare a new property DatabaseParamValues and set the ItemsSourceBinding to it. In the sample project - Players and in the blog post - AvailableCountries. Once you define this property, you may define an expression returning the necessary values depending on each item - just as it is done in the blog post.
You may also take a look at our online documentation for further reference.
Maya
the Telerik team
Many thanks.
I didnt realise that it had to be implemented as a Property. Works now!
Regards
Apoorva