如何在comboBox中设置所选项目或选定值(C#wpf) [英] how set selected item or selected value in comboBox (C# wpf)

查看:1126
本文介绍了如何在comboBox中设置所选项目或选定值(C#wpf)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我用以下代码填充我的组合框:


i fill my combobox with the following code:

<pre> var result = (from a in  dbContext.tbl_Representaion select a).ToList();
            cmbRepresentation.ItemsSource=result;
            cmbRepresentation.DisplayMemberPath = "Name";
            cmbRepresentation.SelectedValuePath = "ID";</pre>





和myXaml代码:



and myXaml Code:

<pre> <ComboBox FlowDirection="RightToLeft" Height=" 25" HorizontalAlignment="Right" Margin="0,6,5,0" Name="cmbRepresentation" SelectedIndex="-1" VerticalAlignment="top" Width="100" SelectionChanged="cmbRepresentation_SelectionChanged" SelectedValue="{Binding Path=SelectedValue, UpdateSourceTrigger=PropertyChanged}" SelectedItem="{Binding SelectedItem}">
           
        </ComboBox

>



现在,如何加载数据,我显示所选值或所选项目所需的ID项目(未选择项目)?

>

now ,how when load data ,I display item for ID required with selected value or selected item(not selectedIndex)?

推荐答案

设置SelectedItem或SelectedIndex
Set either the SelectedItem or the SelectedIndex


这篇关于如何在comboBox中设置所选项目或选定值(C#wpf)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆