本文介绍了如何从ComboBox中的文本块获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有组合框,其中有itemtemplate包含两个文本块,即.对于ID&名称
I have combobox which has itemtemplate which contain two textblock ie. for id & name,
值来自数据库.现在我有一个问题是,如何获取ID或Name的值.
value for ID and Name is come from database. Now I have a Question is that, How i get values of ID or Name.
<ComboBox Name="cmb1" Width="70" ItemsSource="{Binding}"
HorizontalAlignment="Left" Margin="95.5,118.5,0,0" Height="25"
VerticalAlignment="Top" SelectionChanged="cmb1_SelectionChanged">
<ComboBox.ItemTemplate>
<DataTemplate x:Name="cmbDTem">
<StackPanel Orientation="Horizontal">
<TextBlock Name="txtID" Text="{Binding CategoryID}" Width="10"/>
<TextBlock Name="txtName" Text="{Binding CategoryName}" Width="100"/>
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
在Initialize()
In the Initialize()
cmb1.DataContext = ds.Tables[0].DefaultView;
在组合框选择更改中,我要显示选择的值
In Combobox selection changes i want to display the value which selected
private void cmb1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
?????????
}
推荐答案
int categoryID = (cmb1.SelectedItem as MyTableRowClass).CategoryID;
这篇关于如何从ComboBox中的文本块获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!