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

GridViewComboBoxColumn Binding Indexer

4 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Saykor
Top achievements
Rank 2
Saykor asked on 02 May 2014, 12:38 PM
Hi,

In My ViewModel I have: public ObservableCollection<OrderModel> Orders { get; set; }

In OrderModel have: public IEnumerable<utOrderItem> OrderItems { get; set; }

I try to bind this OrderItems to a GridViewComboBoxColumn in RadGridView just to list them:

<telerik:RadGridView Grid.Row="1" Name="grdOrders" ItemsSource="{Binding Orders}" .............

                <telerik:GridViewComboBoxColumn ItemsSource="{Binding Orders[].OrderItems}" Header="Order Items">
                    <telerik:GridViewComboBoxColumn.ItemTemplate>
                        <DataTemplate>
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="Auto"/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="{Binding Quantity}" />
                                <TextBlock Grid.Column="1" Text="{Binding ItemType}" />
                                <TextBlock Grid.Column="2" Text="{Binding UnitPrice}" />
                            </Grid>
                        </DataTemplate>
                    </telerik:GridViewComboBoxColumn.ItemTemplate>
                </telerik:GridViewComboBoxColumn>

                <telerik:GridViewDataColumn DataMemberBinding="{Binding OrderItems.Count}" Header="Order Item Count"/>

Column "Order Items" not show anything
Column "Order Item Count" works

Please advise how I can bind collection that exist in every record?

Best regards,
Saykor





4 Answers, 1 is accepted

Sort by
0
Boris
Telerik team
answered on 05 May 2014, 11:35 AM
Hello Saykor,

I attached a sample project demonstrating how you need to bind the GridViewComboBoxColumn. In order to make the example work we changed a little the provided models ( OrderModel - added OrderModelId property, UtOrderItem - added OrderItemId property). Those changes were necessary if you need to connect the values of the UtOrderItem with the OrderModel.

 In the sample project you can see that in the XAML definition for GridViewComboBoxColumn we are using the ItemsSourceBinding property, because it allows you to bind the ItemsSource of the ComboBox to a property of the data source item(OrderItems). Then you need to bind the DataMemberBinding property to OrderItemId and SelectedValueMemberPath property to OrderModelId.

<telerik:GridViewComboBoxColumn DataMemberBinding="{Binding OrderItemId}"
    DisplayMemberPath="ItemType"
    Header="Order Items"
     ItemsSourceBinding="{Binding OrderItems}"
    SelectedValueMemberPath="OrderModelId">
                    ...
</telerik:GridViewComboBoxColumn>

Please examine the sample project and let us know if this helps.

Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Saykor
Top achievements
Rank 2
answered on 08 May 2014, 01:02 PM
Thank for your demo, Boris.
This work but as I not need to get selected OrderItemID, it is read only for user to see the list of orderItems in order grid. I not need DataMemberBinding and when remove it the dropdown not show anything anymore.

In RadComboBox have a property EmptyText where I can write something like: "Click here to see Order Items". This property do not exist in GridViewComboBoxColumn... why? and how i can do this with GridViewComboBoxColumn?

The alternative of course is to use simple GridViewColumn + RadComboBox:
<telerik:GridViewColumn >
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadComboBox ItemsSource="{Binding OrderItems}" EmptyText="Click here to see Order Items">
                                <telerik:RadComboBox.ItemTemplate>
                                    <DataTemplate>
                                        <Grid DataContext="{Binding}">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="Auto"/>
                                                <ColumnDefinition Width="*"/>
                                                <ColumnDefinition Width="Auto"/>
                                            </Grid.ColumnDefinitions>
                                            <TextBlock Grid.Column="0" Text="{Binding Quantity}" />
                                            <TextBlock Grid.Column="1" Text="{Binding ItemType}" />
                                            <TextBlock Grid.Column="2" Text="{Binding UnitPrice}" />
                                        </Grid>
                                    </DataTemplate>
                                </telerik:RadComboBox.ItemTemplate>
                            </telerik:RadComboBox>
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>

Best regards,
Saykor

0
Saykor
Top achievements
Rank 2
answered on 08 May 2014, 01:05 PM
hmm... little double post here because something was wrong first time when i post a reply but seems still it was save...
If someone can delete one of the posts will be good.
Thanks
0
Accepted
Boris
Telerik team
answered on 08 May 2014, 04:08 PM
Hello Saykor,

The easiest way to list the ComboBox items is as you suggested - to use a GridViewColumn and a RadComboBox. Also, you can set the IsReadOnly property of the GridViewColumn to "True" in order to avoid accidental entering in edit mode.

I hope this helps.

Regards,
Boris Penev
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
Tags
GridView
Asked by
Saykor
Top achievements
Rank 2
Answers by
Boris
Telerik team
Saykor
Top achievements
Rank 2
Share this question
or