Set the selected index of a Combo Box in Grid View Header

2 posts, 0 answers
  1. Dipti
    Dipti avatar
    37 posts
    Member since:
    Dec 2011

    Posted 27 Jan 2012 Link to this post

    Hi,
    I am using RadGridView, whose header contains a ComboBox. I want to be able to set the selected index of the combobox from code behind (let's say when the data is bound to the grid). Please tell me how to do this.

    <telerik:RadGridView x:Name="radGridView" ItemsSource="{Binding PagedSource, ElementName=radDataPager}"
                Grid.ColumnSpan="2" AutoGenerateColumns="False" ShowColumnFooters="True" >
                <telerik:RadGridView.Columns>
                    <telerik:GridViewDataColumn IsFilterable="False" Footer="Total" Width="115" >
                        <telerik:GridViewColumn.Header>
                            <telerik:RadComboBox x:Name="radComboBox" Width="112" SelectionChanged="radComboBox_SelectionChanged">
                                <telerik:RadComboBoxItem Content="Material" />
                                <telerik:RadComboBoxItem Content="Product Group"/>
                            </telerik:RadComboBox>
                        </telerik:GridViewColumn.Header>
                        <telerik:GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Category}" TextAlignment="Right" ToolTipService.ToolTip="{Binding Category}"></TextBlock>
                            </DataTemplate>
                        </telerik:GridViewColumn.CellTemplate>
         </telerik:GridViewDataColumn>
        </telerik:RadGridView.Columns>
     </telerik:RadGridView>
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 01 Feb 2012 Link to this post

    Hi Dipti ,

    There are a few ways of doing this :

    1. In XAML subscribe to the loaded event of the RadComboBox and then in the event handler set the ItemsSource.

    or

    2. Expose your ItemsSource as static resource on the page and use binding to set it .

    *The last but not recommended alternative is to find the combo box in the visual tree and set the itemssource explicitly.

    All the best,
    Pavel Pavlov
    the Telerik team

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

Back to Top