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

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

1 Answer 49 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.
Dipti
Top achievements
Rank 1
Dipti asked on 27 Jan 2012, 02:07 PM
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>

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 01 Feb 2012, 03:39 PM
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 >>

Tags
GridView
Asked by
Dipti
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or