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

[Solved] Problem bind ComboBox in Cell Template

2 Answers 202 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.
Nelson
Top achievements
Rank 1
Nelson asked on 28 Jul 2011, 12:02 PM
Hi,

I want a comboBox in my GridView. I saw some example and I did that:

<telerik:RadGridView
                    Name="GrdConvocados"
                    Background="Transparent"
                    ItemsSource="{Binding OCGrupoParticipantesReuniao}"
                    BorderThickness="0"
                    HorizontalAlignment="Left" Width="Auto" MaxHeight="350" RowHeight="20" Height="300" Grid.Row="1" Grid.Column="0"
                    AutoGenerateColumns="False"
                    SelectionMode="Single"
                    IsReadOnly="True"
                    Cursor="Hand"
                    RowIndicatorVisibility="Collapsed"
                    IsFilteringAllowed="True"
                    ShowGroupPanel="False"
                    ShowColumnFooters="False" ShowInsertRow="False"
                    telerik:RadDragAndDropManager.AllowDrop="True">
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding EntidadesProp.TitulosProp.DesignacaoProp}" Header="TĆ­tulo" Width="0.15*"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding EntidadesProp.TiposentidadeProp.DesignacaoProp }" Header="Tipo Entidade" Width="0.15*"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding EntidadesProp.NomeTratamentoProp}" Header="Nome" Width="0.6*"/>
                <telerik:GridViewDataColumn  Header="Função" Width="0.25*">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.RowDefinitions>
                                    <RowDefinition/>
                                </Grid.RowDefinitions>
                                <telerik:RadComboBox IsEnabled="True" ItemsSource="{Binding OCGrupoParticipantesReuniao}" DisplayMemberPath="EntidadesProp.NomeTratamentoProp"
                                    SelectedItem="{Binding Path=DataContext.ParticipanteSeleccionado.FuncoesreuniaoProp,ElementName=LayoutRoot,Mode=TwoWay}"/>
                            </Grid>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>


The problem is that I can“t bind and populate the comboBox that is inside of Cell Template.
I have a different collection for ComboBox.

Any idea?

2 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 28 Jul 2011, 03:17 PM
Hi Nelson,

 When rows are created , the DataContext is dynamically set to the row item ( your business object) . This means that at a cell level your binding will not work as the context will not be your ViewModel , but the row item instead.

As a solution I may suggest to expose your view model as a static resource and then use it for the binding. This is explained in this help article

Let me know in case you need additional help.

Best wishes,
Didie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Nelson
Top achievements
Rank 1
answered on 28 Jul 2011, 05:36 PM
Hi Didie,

Thanks for the reply.

I did like you said, using a static view model.

<UserControl.Resources>
        <vm:GrupoConvocadosVM x:Key="ConvocadosVM"/>
</UserControl.Resources>

with this I can bind my RadComboBox, but now I have other problem! Now I can“t use this:

                 
<swi:Interaction.Triggers>
                      <swi:EventTrigger EventName="Click">
                          <esi:CallDataMethod Method="LimpaFiltros_Click" />
                      </swi:EventTrigger>
                  </swi:Interaction.Triggers>
              </telerik:RadButton>

Do  you know why?

Thanks
Tags
GridView
Asked by
Nelson
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Nelson
Top achievements
Rank 1
Share this question
or