GridViewComboBoxColumn and SelectedIndex

4 posts, 0 answers
  1. Martin
    Martin avatar
    36 posts
    Member since:
    Sep 2010

    Posted 24 Aug 2011 Link to this post


    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;
                   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";

  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 25 Aug 2011 Link to this post

    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 >>

  3. DevCraft R3 2016 release webinar banner
  4. Martin
    Martin avatar
    36 posts
    Member since:
    Sep 2010

    Posted 29 Aug 2011 Link to this post


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

  5. Scott
    Scott avatar
    1 posts
    Member since:
    Jan 2015

    Posted 20 Jan 2015 Link to this post

    You can assign the index by poiting the SelectedValueMemberPath to an index of your ItemsSource.


    <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]}"  />
Back to Top