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

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

2 Answers 96 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Stephen
Top achievements
Rank 1
Stephen asked on 06 Nov 2012, 09:28 PM
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}"
DisplayMemberPath="HoursTypeCode"
EditTriggers="CellClick"
Header="Hours Type"
IsReadOnlyBinding="{Binding IsRowReadOnly}"
ItemTemplate="{StaticResource EnableTemplate}"
SelectedValueMemberPath="Value"
telerik:TextSearch.TextPath="Text"
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}" />
</telerik:ContainerBindingCollection>
<DataTemplate x:Key="EnableTemplate"
  telerik:ContainerBinding.ContainerBindings="{StaticResource IsEnabledBinding}">
  <TextBlock Text="{Binding Text}" />
</DataTemplate>

2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 09 Nov 2012, 10:02 AM
Hello,
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.

0
Stephen
Top achievements
Rank 1
answered on 12 Nov 2012, 01:48 PM
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.
Tags
GridView
Asked by
Stephen
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Stephen
Top achievements
Rank 1
Share this question
or