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

GridViewComboBoxColumn and SelectedIndex

3 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 24 Aug 2011, 04:30 PM
Hello,

I want to insert a GridViewComboBoxColumn from the Code behind. But I want it to bind to the SelectedIndex not the SelectedValue. How can I manage that?

My code
List<string> listtype = new List<string>();
listtype .Add("A");
               listtype .Add("B");
               listtype .Add("V");
               e.Column.IsVisible = false;
               radGridView1.Columns.Remove(e.Column);
               GridViewComboBoxColumn column = new GridViewComboBoxColumn();
               column.ItemsSource = listtype;
               column.UniqueName = e.Column.UniqueName;
               column.DataType = typeof(short);
               column.DataMemberBinding = new System.Windows.Data.Binding(e.Column.UniqueName);
               column.SelectedValueMemberPath = "Id";
               radGridView1.Columns.Add(column);

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 25 Aug 2011, 08:50 AM
Hi Martin,

The GridViewComboBox column is designed to work with the selected value only. For your scenario I may recommend the following alternative :

Using the CellTemplate and the CellEditTemplate properties of the  GridViewDataColumn you may place a ComboBox or a RadComboBox in the cell . Inside the template you may adjust your bindings having in mind the DataContext is the business object relevant to the row.

In case you have troubles implementing this , just let me know.

Best wishes,
Pavel Pavlov
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Martin
Top achievements
Rank 1
answered on 29 Aug 2011, 08:57 AM
Ok,

I thought there was another way without using the XAML-code.

Thanks
Martin
0
Scott
Top achievements
Rank 1
answered on 20 Jan 2015, 02:45 PM
You can assign the index by poiting the SelectedValueMemberPath to an index of your ItemsSource.

Example:

<telerik:GridViewComboBoxColumn IsReadOnly="False" Header="ISO" DataMemberBinding="{Binding ISOCode}" ValidatesOnDataErrors="Default" 
ItemsSource="{Binding ISOCodes}" SelectedValueMemberPath="{Binding ISOCodes[0]}" />

<telerik:GridViewComboBoxColumn IsReadOnly="False" Header="Cnd." DataMemberBinding="{Binding ConditionCode}" ValidatesOnDataErrors="Default"
ItemsSource="{Binding ConditionCodes}" SelectedValueMemberPath="{Binding ConditionCodes[0]}"  />
Tags
GridView
Asked by
Martin
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Martin
Top achievements
Rank 1
Scott
Top achievements
Rank 1
Share this question
or