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

GridView + ComboBox (+ Enum)

4 Answers 232 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Monika Kogler
Top achievements
Rank 1
Monika Kogler asked on 02 Dec 2009, 03:43 PM
Hi,

I use the RadGridView and I want to have 2 GridViewComboBoxColumn in there. But there are a lot of problem:
1. The Comboboxes should always be visible, but they are only visible if the user double-clicks in the cell. Therefore, I tried to put a normal Combobox in the DataTemplate of the Cell-Template but then
2. Databinding is not working any more. And
3. Databinding with Enums is not working at all. If I bind my enum to the normal GridViewComboBoxColumn the data is showing up wenn the user double clicks, but then it is not possible to select any other cell in the grid and everything stood still.
4. How can I preselect the current dataitem value in the combobox? The initial value of all comboboxes is always empty ....
Please help!

That's my code:
XAML:
<telerik:RadGridView x:Name="grid" Grid.Column="2" Grid.RowSpan="15" AutoGenerateColumns="False" ItemsSource="{Binding}">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Plate Id" DataMemberBinding="{Binding Name}">            
                <telerik:GridViewComboBoxColumn Header="Dilution Factor" DataMemberBinding="{Binding DilutionFactorId, Mode = TwoWay}" ItemsSource="{Binding}" DisplayMemberPath="Name" SelectedValueMemberPath="Id" UniqueName="colDilFactor">
                    <!--<telerik:GridViewComboBoxColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <ComboBox x:Name="internalCboFactor" ItemsSource="{Binding}" SelectedValue="{Binding DilutionFactorId}"></ComboBox>                               
                            </StackPanel>
                        </DataTemplate>
                    </telerik:GridViewComboBoxColumn.CellTemplate>-->
                </telerik:GridViewComboBoxColumn>
                <telerik:GridViewComboBoxColumn Header="State" DataMemberBinding="{Binding State}" ItemsSource="{Binding}" UniqueName="colState">
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

C#
((GridViewComboBoxColumn)grid.Columns["colState"]).ItemsSource = Enum.GetNames(typeof(PlateStateEnum));
 ((GridViewComboBoxColumn)grid.Columns["colDilFactor"]).ItemsSource =                     _handler.GetProvider().LoadDilutionFactors(typeId);

                //ComboBox cboFactor = grid.Columns["colDilFactor"].FindName("internalCboFactor") as ComboBox;
                //if(cboFactor != null)
                //    cboFactor.ItemsSource = _handler.GetProvider().LoadDilutionFactors(typeId);

            }

Thx in advance!

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 07 Dec 2009, 06:01 PM
Hi Monika Kogler,

 I have prepared a small sample application for you .
It demonstrates an always visible ComboBox in a cell (placed  via CellTemplate) . The combo is pre-populated with the underlying value as required.

Let me know if you have any troubles adapting this to your project.

Regards,
Pavel Pavlov
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Monika Kogler
Top achievements
Rank 1
answered on 09 Dec 2009, 12:40 PM
Hi,
thanks for the example. Actually, I need several ComboBoxes in 1 Grid, and so gridview.itemsource = itemsource won't work for me. So how can I bind the Itemsource of each Combobox individually? I have tried to access each GridViewColumn via (GridViewDataColumn)gridPlates.Columns["uniqueColName"] but GridViewDataColumn does not have an Itemsource ... So how can I do it?
And: Is there no easier way to bind an enum? Need I really all these wrapper?
Thx in advance
0
Pavel Pavlov
Telerik team
answered on 11 Dec 2009, 10:12 AM
Hello Monika Kogler,

The modified example attached demonstrates the same approach but with two columns with different itemssources . The same way you can set as  many columns  as you need. 

Regards,

Pavel Pavlov
the Telerik team

 


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tony Mocella
Top achievements
Rank 1
answered on 24 Feb 2010, 01:52 PM
Thank you for posting this - it solves the exact problem I was having with ComboBox columns in the GridView.
Tags
GridView
Asked by
Monika Kogler
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Monika Kogler
Top achievements
Rank 1
Tony Mocella
Top achievements
Rank 1
Share this question
or