[英]data binding in wpf combo box in data grid
I am having one problem related to ComboBox
of DataGrid
. 我有一个与
DataGrid
ComboBox
相关的问题。 Data is binding but it is not showing in the ComboBox
after binding. 数据正在绑定,但绑定后未显示在
ComboBox
。 My code is like below: 我的代码如下:
<my:DataGridTemplateColumn Header="UsgSrc">
<my:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cbUsgSrc"
ItemsSource="{Binding Source={StaticResource UsgSrcUOMS}}"
SelectedValue="{Binding Path=UsgSrc}"
SelectedValuePath="UtType"
DisplayMemberPath="UtType">
</ComboBox>
</DataTemplate>
</my:DataGridTemplateColumn.CellTemplate>
</my:DataGridTemplateColumn>
Code for static resource: 静态资源代码:
UsgSrcUOMS.ObjectDataProvider UsageSrcUOMS = null;
UsageSrcUOMS = (ObjectDataProvider)FindResource("UsgSrcUOMS");
UsageSrcUOMS.ObjectInstance = objUtView;
Microsoft.Windows.Controls.DataGridCell cell = obj.GetCell(dgMtrHdr, J, 11);
if (cell != null)
{
ContentPresenter panel = cell.Content as ContentPresenter;
if (panel != null)
{
ComboBox cmbUsUtilit = obj.GetVisualChild<ComboBox>(panel);
cmbUsUtilit.IsEnabled = true;
if(objUtView!=null)
cmbUsUtilit.ItemsSource = objUtView;cmbUsUtilit.SelectedIndex=2;
}
}
What is the reason for this. 这是什么原因。 Please help me to solve my problem.
请帮助我解决我的问题。
Have you tried to change the Binding to the StaticResource, something like that 您是否尝试过将Binding更改为StaticResource,诸如此类
<ComboBox Name="cbUsgSrc"
ItemsSource="{StaticResource UsgSrcUOMS}"
SelectedValue="{Binding Path=UsgSrc}"
SelectedValuePath="UtType"
DisplayMemberPath="UtType">
</ComboBox>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.