This is a migrated thread and some comments may be shown as answers.

GridviewCombobox with multiple data source

4 Answers 94 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Apoorva
Top achievements
Rank 1
Apoorva asked on 13 May 2011, 05:08 PM
Hi
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

Sort by
0
Maya
Telerik team
answered on 16 May 2011, 06:38 AM
Hi Apoorva,

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.

Regards,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Apoorva
Top achievements
Rank 1
answered on 16 May 2011, 09:39 AM
Hi Maya
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>
and the code for the classes is here:
    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;
    }
}
This is what I do at the form load:
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();
Am I missing something?

Regards
Apoorva
0
Accepted
Maya
Telerik team
answered on 16 May 2011, 10:03 AM
Hello 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.

All the best,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Apoorva
Top achievements
Rank 1
answered on 16 May 2011, 10:34 AM
Hi Maya
Many thanks.
I didnt realise that it had to be implemented as a Property. Works now!

Regards
Apoorva
Tags
GridView
Asked by
Apoorva
Top achievements
Rank 1
Answers by
Maya
Telerik team
Apoorva
Top achievements
Rank 1
Share this question
or