组合框DisplayMember的值

时间:2022-11-29 20:32:33

I'm pretty new to WPF and searched several sites and pages, but didn't really found my problem:

我是WPF的新手并搜索了几个网站和页面,但没有真正找到我的问题:

I fill my Combobox with values and different displaymembers

我为我的Combobox填充了价值观和不同的显示成员

C#:

C#:

comboRaum.DataContext = dtLoad.DefaultView;
        comboRaum.DisplayMemberPath = dtLoad.Columns["Name"].ToString();
        comboRaum.SelectedValuePath = dtLoad.Columns["ID_Room"].ToString();

XAML:

XAML:

<ComboBox Name="comboRaum" Margin="5" Height="26" ItemsSource="{Binding}"/>

Now I read the ID_Room from ANOTHER table with an SQLDataReader. The reader works fine, all other things are displayed right.

现在我用一个SQLDataReader从另一个表中读取ID_Room。读者工作正常,所有其他事情都正确显示。

sqlreaderDetails["ID_Room"].ToString();

How do I get my Combobox to set the item with the same value as the selected item? It jumps always to the first entry.

如何让我的Combobox设置与所选项目具有相同值的项目?它总是跳到第一个条目。

1 个解决方案

#1


0  

Solved it!

解决了!

Added

添加

SelectedValuePath="Content"

To my XAML Combobox properties. Now I can set the SelectedItem with SelectedValue = ID at runtime.

到我的XAML Combobox属性。现在我可以在运行时使用SelectedValue = ID设置SelectedItem。

#1


0  

Solved it!

解决了!

Added

添加

SelectedValuePath="Content"

To my XAML Combobox properties. Now I can set the SelectedItem with SelectedValue = ID at runtime.

到我的XAML Combobox属性。现在我可以在运行时使用SelectedValue = ID设置SelectedItem。