GridViewComboBoxColumn Binding Indexer

5 posts, 1 answers
  1. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 02 May 2014 Link to this post

    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





  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 05 May 2014 Link to this post

    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.
     
  3. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 08 May 2014 Link to this post

    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

  4. Saykor
    Saykor avatar
    70 posts
    Member since:
    Feb 2011

    Posted 08 May 2014 Link to this post

    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
  5. Answer
    Boris
    Admin
    Boris avatar
    276 posts

    Posted 08 May 2014 Link to this post

    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.
     
Back to Top