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

GridView Editable with ComboBox Column

7 Answers 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Missing User
Missing User asked on 24 Oct 2011, 03:08 PM
Hello!.

I have a Master grid, with Row Details, inside the RowDetailsTemplate i have another GridView that are Editable. In this Grid the user can insert new rows and fill the cell with the values. One of the Column have a Combobox inside of it, but when the user click to add a New row, the ComboBox doens't appers in the Cell.

Here some code.

MasterGrid.
<telerik:RadGridView x:Name="GridViewNegocios"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="2"
                                         HorizontalAlignment="Left"
                                         AutoGenerateColumns="False"
                                         CellEditEnded="GridViewNegocios_CellEditEnded"
                                         RowDetailsVisibilityChanged="GridViewNegocios_RowDetailsVisibilityChanged"
                                         RowDetailsTemplate="{StaticResource GridSegmentoDetalhesTemplate }"
                                         LoadingRowDetails="GridViewNegocios_LoadingRowDetails"
                                         RowDetailsVisibilityMode="VisibleWhenSelected"
                                         VerticalAlignment="Top"
                                         IsBusy="{Binding GridNegociosBusy, Mode=TwoWay}"
                                         Margin="5,20,5,20"
                                         telerik:StyleManager.Theme="Office_Silver">

Details Grid
<telerik:RadGridView x:Name="GridViewSegmentos"
                                 AutoGenerateColumns="False"
                                 Grid.Row="2"
                                 Grid.Column="0"
                                 ShowGroupPanel="False"
                                 CanUserInsertRows="True"
                                 HorizontalAlignment="Left"
                                 Loaded="GridViewSegmentos_Loaded"
                                 ShowInsertRow="True"
                                 Margin="5,10,5,15"
                                 RowEditEnded="GridViewSegmentos_RowEditEnded"                           
                                 telerik:StyleManager.Theme="Office_Silver"
                                 Grid.ColumnSpan="2">

Attached are a image, that shows the problem.

Maybe I'm missing something, can you help me with this?

Thank you!

7 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 24 Oct 2011, 03:46 PM
Hello Joao,

Could you provide a bit more details on your settings ? How do you define your columns ?
It would be great if you could share some relevant code-snippets.

Kind regards,
Maya
the Telerik team

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

0
Missing User
answered on 24 Oct 2011, 04:15 PM
Hi, sure:

This is my MasterGrid Declaration:

<telerik:RadGridView x:Name="GridViewNegocios"
                                         Grid.Row="1"
                                         Grid.Column="0"
                                         Grid.ColumnSpan="2"
                                         HorizontalAlignment="Left"
                                         AutoGenerateColumns="False"
                                         CellEditEnded="GridViewNegocios_CellEditEnded"
                                         RowDetailsVisibilityChanged="GridViewNegocios_RowDetailsVisibilityChanged"
                                         RowDetailsTemplate="{StaticResource GridSegmentoDetalhesTemplate }"
                                         LoadingRowDetails="GridViewNegocios_LoadingRowDetails"
                                         RowDetailsVisibilityMode="VisibleWhenSelected"
                                         VerticalAlignment="Top"
                                         IsBusy="{Binding GridNegociosBusy, Mode=TwoWay}"
                                         Margin="5,20,5,20"
                                         telerik:StyleManager.Theme="Office_Silver">
                        <telerik:RadGridView.Columns>
 
                            <telerik:GridViewToggleRowDetailsColumn ExpandMode="Single" />
 
                            <telerik:GridViewDataColumn Header="NegócioID"
                                                        DataMemberBinding="{Binding ObjNegocio.NegocioID}"
                                                        IsVisible="False" />
 
                            <telerik:GridViewDataColumn Header="Negócio"
                                                        DataMemberBinding="{Binding ObjNegocio.Negocio}"
                                                        IsVisible="True" />
 
                            <telerik:GridViewDataColumn Header="PeríodoID"
                                                        DataMemberBinding="{Binding ObjPeriodo.PeriodoID}"
                                                        IsVisible="False" />
 
                            <telerik:GridViewDataColumn Header="Período"
                                                        DataMemberBinding="{Binding ObjPeriodo.Periodo}"
                                                        IsVisible="True" />
 
                            <telerik:GridViewDataColumn Header="NegócioAplicacaoID"
                                                        DataMemberBinding="{Binding ObjAplicacaoNegocio.AplicacaoNegocioID}"
                                                        IsVisible="False" />
 
                            <telerik:GridViewDataColumn Header="Aplicação"
                                                        DataMemberBinding="{Binding ObjAplicacaoNegocio.AplicacaoNegocio}" />
 
                            <telerik:GridViewDataColumn Header="PessoaNegocioPeriodoID"
                                                        DataMemberBinding="{Binding PessoaNegocioPeriodoID}"
                                                        IsVisible="False" />
 
                            <telerik:GridViewDataColumn Header="Qtde"
                                                        DataMemberBinding="{Binding Quantidade}"
                                                        />
 
                            <telerik:GridViewDataColumn Header="Custos"
                                                        DataMemberBinding="{Binding ValorTotalCusto, StringFormat=\{0:n2\}}"/>
 
                            <telerik:GridViewDataColumn Header="Potencial"
                                                        Background="Bisque"
                                                        DataMemberBinding="{Binding Converter={StaticResource ExpressionCollumnConverter}, Mode=OneWay, StringFormat=\{0:n2\}}" />
 
                        </telerik:RadGridView.Columns>
                    </telerik:RadGridView>

And this is de Details Grid Declaration:

<DataTemplate x:Key="GridSegmentoDetalhesTemplate">
            <telerik:RadGridView x:Name="GridViewSegmentos"
                                 AutoGenerateColumns="False"
                                 Grid.Row="2"
                                 Grid.Column="0"
                                 ShowGroupPanel="False"
                                 CanUserInsertRows="True"
                                 HorizontalAlignment="Left"
                                 Loaded="GridViewSegmentos_Loaded"
                                 ShowInsertRow="True"
                                 Margin="5,10,5,15"
                                 RowEditEnded="GridViewSegmentos_RowEditEnded"                           
                                 telerik:StyleManager.Theme="Office_Silver"
                                 Grid.ColumnSpan="2">
 
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn Header="PessoaNegocioSegmento"
                                                DataMemberBinding="{Binding PessoaNegocioSegmentoID}"
                                                IsVisible="False"/>
                     
                    <telerik:GridViewDataColumn Header="Segmento">
                        <telerik:GridViewDataColumn.CellTemplate>
                            <DataTemplate>
                                <telerik:RadComboBox x:Name="cmbSegmentos"
                                                     Loaded="cmbSegmentos_Loaded"
                                                     SelectedValue="{Binding SegmentoID, Mode=TwoWay}"
                                                     Width="100"/>
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellTemplate>
                    </telerik:GridViewDataColumn>
 
                    <telerik:GridViewDataColumn Header="Valor Custo"
                                                DataMemberBinding="{Binding ValorCusto, StringFormat=\{0:n2\}}" />
 
                    <telerik:GridViewDataColumn Header="PessoaNegocioPeriodoID"
                                                DataMemberBinding="{Binding PessoaNegocioPeriodoID}"
                                                IsVisible="False"/>
 
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>
        </DataTemplate>

Since the ComboBox is inside a DataTemplate I use it's Loaded Event to assing the ItemSource  and the Binding to it. Like this:

private void cmbSegmentos_Loaded(object sender, RoutedEventArgs e)
        {
            this.ComboGridSegmento = sender as RadComboBox;
            this.ComboGridSegmento.ItemsSource = ViewModel.obcComboNegocioSegmento;
 
 
            this.ComboGridSegmento.DisplayMemberPath = "Descricao";
            this.ComboGridSegmento.SelectedValuePath = "Codigo";
 
            //Setar o Binding
            Binding binding = new Binding("SegmentoID");
            binding.Mode = BindingMode.TwoWay;
            this.ComboGridSegmento.SetBinding(RadComboBox.SelectedValueProperty, binding);
 
        }

Note, in this way the combo have the items that comes from a List in my ViewModel, it just don't show up when a new row is inserted on RadGridView.
0
Maya
Telerik team
answered on 25 Oct 2011, 02:03 PM
Hello Joao Paulo Grassi,

I have tried to reproduce the issue you reported, but unfortunately without any success. Would you take a look at the sample to verify whether I am testing it correctly and whether you can reproduce the same behavior on it ?
 

Greetings,
Maya
the Telerik team

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

0
Missing User
answered on 26 Oct 2011, 12:59 PM
Hi Maya,

Thanks for your help, I look into your sample project, and I found something, my ComboBox is in the First column of the GridView, yours is in the Last, When I change the columns and send the combo to the last one, it works!.

Now, my only problem is, when I Call my WCF Service that returns a List of Objects to fill my Details Grid, my combo don't get the old value selected, but in this list i have the ID present in the combo, do you know why it don't be selected automatically?

Note: The ID aren't Int Values, they are GUID, i don't know if this is some kind of problem.

Thank you!
0
Maya
Telerik team
answered on 27 Oct 2011, 09:10 AM
Hi Joao Paulo Grassi,

In order to suggest any further, I would need a bit more details. Is the data for the combo box and the details grid available  ? Is there an item from the source of the combo corresponding to the GUID property from the business object for the child grid - you need to have equal values so that the corresponding item from the source of the column is displayed ? How do you set the ItemsSource of the column ?

Best wishes,
Maya
the Telerik team

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

0
Missing User
answered on 27 Oct 2011, 11:56 AM
Hi again Maya,

Answering your questions:

Yes, the data for combo box and details grid are available.
Yes, there's an item in the combo box source with the corresponding GUID from the details grid source.

Since i need to check for new data everytime that a row details is expanded I attached  this on this event of the master grid:

private void GridViewNegocios_RowDetailsVisibilityChanged(object sender, GridViewRowDetailsEventArgs e)
        {
            this.ViewModel.ListaGridSegmentos.Clear();
 
            if (e.Visibility == Visibility.Visible)
            {
                PRJ_PessoaNegocioPeriodo row = e.Row.DataContext as PRJ_PessoaNegocioPeriodo;
                                            //This call in my ViewModel a WCF service, and returns a  List of Objects for the combobox
                this.ViewModel.RecuperarSegmentosCombo(row.ObjNegocio.NegocioID);
                      //And this call other WCF service, and returns a list for my details grid
                this.ViewModel.RecuperarListaPessoaNegocioSegmento(row.PessoaNegocioPeriodoID);
                this.ViewModel.objPessoaNegocioPeriodo = row;
            }
        }

You see, in the RowDetailsVisibilityChanged I call my methods to fill both grid and combo box, because i need
to look to different data in any master row when they are "expanded". These methods are async so, maybe this can causing this issue?

There's also other problem, on the combo box collumn if i set the DataMemberBinding like this.
DataMemberBinding="{Binding SegmentoID, Mode=TwoWay}"
When I try to change the item of the combo on any row that is already saved, it just don't select, it returns to the index 0. If i remove the DataMemberBinding it works normally.

PS: I'm using this version of controls: 2010.2.812.1040
0
Maya
Telerik team
answered on 01 Nov 2011, 01:18 PM
Hello Joao Paulo Grassi,

My first recommendation would be to try with our current official release and test whether you get the same behavior. Furthermore, you definitely need setting DataMemberBinding of GridViewComboBoxColumn (and actually there is no need to set the Mode to "TwoWay'). If the item you select from the combo box is not saved as the selected one, probably the reason is somewhere in the way you define the bindings depending on the underlying business objects. Will it be possible to simulate the same behavior on the project I previously attached ?  
 

Best wishes,
Maya
the Telerik team

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

Tags
GridView
Asked by
Missing User
Answers by
Maya
Telerik team
Missing User
Share this question
or