ComboBox inside GridView: Cannot get the data value from the grid source to show up.

3 posts, 0 answers
  1. Stephen
    Stephen avatar
    43 posts
    Member since:
    Apr 2012

    Posted 06 Nov 2012 Link to this post

    I have a grid view, with a combo box inside it.  The combo box works great.  It has the items in it, you can select them, and when you select something, the value shows up correctly in the grid.  The problem I am having is that the initial value in the column, which comes from the grid's data source, doesn't show.  I have done combo boxes in grids before, but this is the first I have done one that has an item template.

    Here is the code from my XAML:
    <telerik:GridViewComboBoxColumn DataMemberBinding="{Binding Value}"
    ItemsSource="{Binding Items}"
    Header="Hours Type"
    IsReadOnlyBinding="{Binding IsRowReadOnly}"
    ItemTemplate="{StaticResource EnableTemplate}"
    UniqueName="rcbxGridHoursType" />

    HoursTypeCode is the database value name for the column, from the Grid's data source
    Text is what should show up in the combo box item list
    Value is the code behind the Text in the combo box

    I would have thought that DataMemberBinding would be where I put HoursTypeCode, but when I do that, it breaks the combobox and it ends up with no items in it.

    Here is the code for the template, which I am using in other places and it works fine, but I thought I would include it:
    <telerik:ContainerBindingCollection x:Key="IsEnabledBinding">
      <telerik:ContainerBinding PropertyName="IsEnabled" Binding="{Binding IsEnabled, Mode=TwoWay}" />
    <DataTemplate x:Key="EnableTemplate"
      telerik:ContainerBinding.ContainerBindings="{StaticResource IsEnabledBinding}">
      <TextBlock Text="{Binding Text}" />
  2. Pavel Pavlov
    Pavel Pavlov avatar
    2039 posts

    Posted 09 Nov 2012 Link to this post

    According to your description it appears the Combo is properly set , however initially it could not make a match between the value in the cell and an item of its own ItemsSource.

    Please check the initial value of the cell is correct ( e.g. displaying it with a regular column rather than a combo column) .
    Also the types must be the same.

    Kind regards,
    Pavel Pavlov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Stephen
    Stephen avatar
    43 posts
    Member since:
    Apr 2012

    Posted 12 Nov 2012 Link to this post

    What I did was set the item source in C#, instead of binding it to Items in the XAML.  When I did that, it worked fine.
Back to Top