如何在Silverlight代码中将选定的值设置为Combobox

时间:2013-08-12 04:02:39

标签: datagrid silverlight-4.0

如何在Silverlight代码中将所选值设置为Combobox。

代码如下:

<sdk:DataGridTemplateColumn Header="Risk">
                        <sdk:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Grid>
                                    <ComboBox Height="Auto" x:Name="ComboRisk" Width="110" ItemsSource="{Binding Path=CusList,Mode=TwoWay}" SelectedValuePath="{Binding Path=Risk, Mode=OneWay}" SelectedItem="{Binding Mode=OneWay, Path=Risk}">
                                        <ComboBoxItem Content="High" Background="#55A3FF" IsEnabled="False" Margin="1,2,0,0" />
                                        <ComboBoxItem Content="Test Time" Margin="8,2,4,4" />
                                        <ComboBoxItem Content="Yield Hit" Margin="8,2,4,4" />
                                        <ComboBoxItem Content="Quality Impact (DPPM/Reli)" Margin="8,2,4,4" />
                                        <ComboBoxItem Content="Breaking Download" Margin="8,2,4,4" />
                                        <ComboBoxItem Content="ROM Update" Margin="8,2,4,4" />
                                        <ComboBoxItem Content="Low" Background="#55A3FF" Margin="1,2,0,0" IsEnabled="False" />
                                        <ComboBoxItem Content="Good to go" Margin="8,2,4,4" />
                                    </ComboBox>
                                </Grid>
                            </DataTemplate>
                        </sdk:DataGridTemplateColumn.CellTemplate>
                    </sdk:DataGridTemplateColumn>
代码背后的

我这样做:

   ComboRisk.SelectedItem = bcomstask.Risk.ToString()

1 个答案:

答案 0 :(得分:0)

这很好。

int intCounter = 0;
            foreach(ComboBoxItem currentItem in cboCategory.Items)
            {
                if (currentItem.Content.ToString() == "Time Out")
                    break;
                intCounter++;
            }
            cboCategory.SelectedIndex = intCounter;