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

ComboBox not intializing with selected value.

1 Answer 34 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Hazzard
Top achievements
Rank 1
Hazzard asked on 01 Nov 2011, 11:54 PM

I am trying to not only populate the combobox within the gridview with just 2 values, but I want the first value to be displayed when the page loads. How do I accomplish that? As you can see in my xaml, I'm trying about everything I can think of.  Thank you.
combo box not initialzing to first value

<l:Collection x:Key="EMC_Classes">
    <!-- Collection<object> -->
    <l:EMC_Class ID="1" Class="A or B" />
    <l:EMC_Class ID="2" Class="A,B,C,D" />
</l:Collection>
  
<l:ValueToItemConverter x:Key="EMCID2Class"
                    ItemsSource="{StaticResource EMC_Classes}"
                    ValuePath="ID"
                    DisplayMemberPath="Class" />
  
<telerik:GridViewColumn Header="Class" Width="100" IsReadOnly="False" x:Name="ComboClass">
    <telerik:GridViewColumn.CellTemplate>
        <DataTemplate >
            <ComboBox FontSize="10"   Width="90" HorizontalAlignment="Center" 
                    ItemsSource="{StaticResource EMC_Classes}"
                    DisplayMemberPath="Class"
                    SelectedValuePath="ID"
                    SelectedValue="1"
                    SelectedIndex="1"
                    SelectedItem="1"
                    SelectionChanged="ComboBox_SelectionChanged"
                />
        </DataTemplate>
    </telerik:GridViewColumn.CellTemplate>
</telerik:GridViewColumn>

public void GridLoaded(object sender, TypeLoadedEventArgs e)
{
   MyAppliedStandardsModels = new ObservableCollection<AppliedStandardsModel>();
   var emcClasses = new List<EMC_Class>();
   foreach (AppliedStandardsModel item in e.SType)
   {
      MyAppliedStandardsModels.Add(item);
   }
      rgvEMCTestPlans.ItemsSource = MyAppliedStandardsModels;
   }
  
  
 public class EMC_Class
 {
    public string Class { get; set; }
    public int ID { get; set; }
 }
  
private ObservableCollection<AppliedStandardsModel> _myAppliedStandardsModel;
  
public ObservableCollection<AppliedStandardsModel> MyAppliedStandardsModels
{
    get { return _myAppliedStandardsModel; }
    set
    {
        _myAppliedStandardsModel = value;
        FirePropertyChanged("MyAppliedStandardsModel");
    }
}

1 Answer, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Nov 2011, 06:52 AM
Hello Hazzard,

You need to define DataMemberBinding of the column as otherwise this column will not know which is the property it corresponds to from the underlying data item. Consequently, it will not be able to display it. Another possible way would be to bind the SelectedValue property of the combo box, but in this way you will not be able to sort, filter and group.
I will definitely recommend you to run through our online documentation considering columns, the way you have define them and how you can change their cell and cell edit templates.
Still, let me know if you need any further assistance.
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

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