datagrid问题中的组合框-在文本框中显示组合的属性 [英] Combobox in datagrid question - displaying a property of the combo in a textbox

查看:66
本文介绍了datagrid问题中的组合框-在文本框中显示组合的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将组合框的属性放在数据网格的文本框中.

I'd like to put a property of a combobox in a textbox on a datagrid.

组合如下定义的数据网格:

Combo in a datagrid defined like so:

 

Xaml:

                        <DataGridTemplateColumn x:Name="cboPartBCPT" Header="CPT Code" Width="100" >
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="{Binding CPT}" />
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>

                            <DataGridTemplateColumn.CellEditingTemplate >
                                <DataTemplate>
                                    <ComboBox x:Name="cboPartBCPT"
                                                ItemsSource="{Binding Source = {StaticResource PartB_CPTLookup}}"
                                                SelectedValue="{Binding Path=CPT}"
                                                SelectedValuePath="CPT"
                                                DisplayMemberPath="CPT"
                                                           IsSynchronizedWithCurrentItem="True">
                                    </ComboBox>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellEditingTemplate>
                        </DataGridTemplateColumn>

                        <DataGridTextColumn x:Name="PartBProcedure" Header="Procedure" Width="200"
                                            Binding="{Binding SelectedItem.ProcedureName, ElementName=cboPartBCPT}" />

PartBProcedure始终为空白.我在做什么错了?

PartBProcedure is always blank. What am I doing wrong?

谢谢.

推荐答案

在更改ComboBox中的选择时,DataGridTextColumn应该绑定到正在设置的CPT属性.为了发生更改通知,您的类应实现INotifyPropertyChanged并在CPT时引发PropertyChanged事件 属性已设置:

The DataGridTextColumn should bind to the CPT property that is being set when you change selection in the ComboBox. For change notification to occur, your class should implement the INotifyPropertyChanged and raise the PropertyChanged event when the CPT property is being set:

Partial Public Class tlkpProcedures_PartB
    Implements INotifyPropertyChanged

Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub

Private cpt As String = String.Empty
 Public Property CPT() As String
        Get
            Return Me.cpt
        End Get

        Set(ByVal value As String)
             Me.cpt = value
                NotifyPropertyChanged("CPT")
        End Set
    End Property

...

End Class

  <DataGridTextColumn x:Name="PartBProcedure" Header="Procedure" Width="200"
                                            Binding="{Binding CPT}" />






这篇关于datagrid问题中的组合框-在文本框中显示组合的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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