This question is locked. New answers and comments are not allowed.
Hi,
I'm trying to set the SelectedItem on 3 ComboBoxs that are in a ControlTemplate in in a GridView Column. The ComboBoxes are getting bound to their ItemsSources during the ComboBoxes Loaded event. I would like to set the SelectedItem for the ComboBoxes based on values bound to the GridViewRow.
I thought I might be able to do it using the RowLoaded event but I can't seem to figure out how to access the ComboBoxes from there.
Any help would be greatly appreciated.
I'm trying to set the SelectedItem on 3 ComboBoxs that are in a ControlTemplate in in a GridView Column. The ComboBoxes are getting bound to their ItemsSources during the ComboBoxes Loaded event. I would like to set the SelectedItem for the ComboBoxes based on values bound to the GridViewRow.
| <grid:GridViewDataColumn HeaderText=""> |
| <grid:GridViewColumn.CellStyle> |
| <Style TargetType="gridView:GridViewCell"> |
| <Setter Property="Template"> |
| <Setter.Value> |
| <ControlTemplate TargetType="gridView:GridViewCell"> |
| <StackPanel Orientation="Vertical"> |
| <TextBlock>Stage:</TextBlock> |
| <ComboBox x:Name="cbStage" SelectedItem="{Binding Stage}" Loaded="cbStage_Loaded" /> |
| <TextBlock>Advisor:</TextBlock> |
| <!--ComboBox x:Name="cbAdvisor" /--> |
| <TextBlock>Sponsor:</TextBlock> |
| <!--ComboBox x:Name="cbSponsor" /--> |
| </StackPanel> |
| </ControlTemplate> |
| </Setter.Value> |
| </Setter> |
| </Style> |
| </grid:GridViewColumn.CellStyle> |
| </grid:GridViewDataColumn> |
| private void cbStage_Loaded(object sender, RoutedEventArgs e) |
| { |
| ComboBox cb = (ComboBox)sender; |
| if (stageListData != null) |
| { |
| string[] source = new string[stageListData.Count + 1]; |
| source[0] = "No Stage"; |
| for (int i = 0; i < stageListData.Count; i++) |
| { |
| source[i + 1] = stageListData[i].StageName; |
| } |
| cb.ItemsSource = source; |
| } |
| else |
| { |
| string[] source = new string[1]; |
| source[0] = "No Stage"; |
| cb.ItemsSource = source; |
| } |
| } |
I thought I might be able to do it using the RowLoaded event but I can't seem to figure out how to access the ComboBoxes from there.
Any help would be greatly appreciated.