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

[Solved] RadGridView and RadComboBox column

2 Answers 171 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.
Lars
Top achievements
Rank 1
Lars asked on 01 Jul 2011, 04:30 PM
Hello,

I alread looked up nearly a hundred threads about this theme but I still have problems achieving a more or less simple task. I would be very happy in case someone could help me out:

I would like to display several columns in a RadGridView. If the user clicked on the first column, it should turn into a (autofill) RadComboBox.

I dynamically (gvCars.ItemsSource=xx) bound the RadGridView to an ObserveableCollection of my type, let's say ObserveableCollection<Cars> and it displays the following entries:

Brand | Year | Price
VW       2010   27.102 €
BMW    2011   57.102 €

This works fine.

However, when I click on the "Brand" column, I would like it to switch to the RadComboBox control so that the user can select one of the values which are in my ObserveableCollection<string>theBrands variable, which is just a list of strings like "VW","BMW","Porsche" etc.

public ObservableCollection<string> theBrands { get; set; }

// ... within the source code I do the following:
theBrands.Add("VW");
theBrands.Add("BMW");
theBrands.Add("Porsche...");

// I even tried adding the fields before calling InitializeComponents(), no effekt.

What happens in my app is that the column "Brand" turns into the RadComboBox (yippie!) but I cannot select anything from the RadComboBox (it does not even drops) as if the 'theBrands' collection was empty (but it is not).

Second problem: If the user had the opportunity to select some other brand from the RadComboBox, I would like this brand to be stored back in the ObserveableCollection<Cars> again (eg in  the "Brand" property of the "Cars" class) or somewhere else where I can exchange the previous value with the newly selected value.

So I have two ObservableCollections, one for the "real" data (displayed in the grid) and one especially only for the RadComboBox selection choices.

My XAML currently looks like this:

<telerik:RadGridView  telerik:StyleManager.Theme="Vista" RowValidating="GridView_RowValidating" 
CellValidating="GridView_CellValidating" BeginningEdit="GridView_BeginningEdit"
RowEditEnded
="GridView_RowEditEnded" AddingNewDataItem="GridView_AddingNewDataItem"
Margin="120,25,32,31" Name="gvCars" Grid.Row="2" TabIndex="6" AutoGenerateColumns="False"
SelectionMode
="Multiple" ShowGroupFooters="False" ShowInsertRow="True" ActionOnLostFocus="CancelEdit"
CanUserSelect="True">
            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Brand, Mode=TwoWay}"  Header="Brand">
                    <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox Name="cbBrand" IsEditable="True" CanAutocompleteSelectItems="true"  ItemsSource="{Binding theBrands, Mode=TwoWay}"/>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellEditTemplate>
                </telerik:GridViewDataColumn>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Year, Mode=TwoWay}" Header="Year" IsReadOnly="True"/>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Price, Mode=TwoWay}" Header="Price"/>
            </telerik:RadGridView.Columns>
        </telerik:RadGridView>

Can you help me out please?

Thank you,
Lars.



2 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 04 Jul 2011, 10:02 AM
Hi Lars,

Are you looking for something like that ?.

Kind regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Lars
Top achievements
Rank 1
answered on 06 Jul 2011, 01:50 PM
Hello,

thank you for your link but it was not even close to my problem.
It seems like it is not possible to bind a CellEditTemplate correctly using XAML only. An indicator for this seems to be that the Visual Studio 2010 property editor cannot be used for CellEditTemplate and the Telerik Grid component at all. It is disabled whereas I can use it eg. with the free SilverlightToolkit Grid control. Maybe Telerik corrects this in the future?
What I now did is using C# and the 'Loaded' event to bind the data to the RadComboBox, just like doing it in the "good old days" of GUI programming.

Thanks anyway,
Lars.
Tags
GridView
Asked by
Lars
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Lars
Top achievements
Rank 1
Share this question
or