WPF数据绑定gridview问题

时间:2012-11-25 06:09:03

标签: wpf

我正在处理从Entity模型填充的dataGrid。我在特定列中有以下内容,尝试在编辑期间使用组合框,编辑源是CollectionsViewSource。

      <Grid DataContext="{StaticResource vsLogins}" Grid.Column="1" 
            Margin="16,248,154,31">
        <DataGrid AutoGenerateColumns="False" EnableRowVirtualization="True" 
                  Height="213" HorizontalAlignment="Left"
                  ItemsSource="{Binding Source={StaticResource vsLogins}}" 
                  Name="LoginsDataGrid"
                  RowDetailsVisibilityMode="VisibleWhenSelected" 
                  VerticalAlignment="Top" Width="380"
                  Background="{StaticResource lgb}" BorderThickness="2" 
                  BorderBrush="#FFFC0303">
          <DataGrid.Columns>
            <DataGridTextColumn x:Name="LoginNameColumn" Binding="{Binding 
                                  Path=LoginName}" Header="Login Name"
                                  Width="200" MinWidth="200" />
            <DataGridTextColumn x:Name="PsWrdColumn"
                                Binding="{Binding Path=PsWrd}" 
                                Header="Password" Width="130" MinWidth="130" />
            <DataGridTemplateColumn x:Name="AccessLevelIdColumn" Header="Id"
                                    Width="40" MinWidth="40">
              <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                  <TextBlock Text="{Binding Path=AccessLevelId}" />
                </DataTemplate>
              </DataGridTemplateColumn.CellTemplate>
              <DataGridTemplateColumn.CellEditingTemplate>
                <DataTemplate>
                  <ComboBox ItemsSource="{Binding Source={StaticResource 
                             vsAccessLevels}}" DisplayMemberPath="Description" 
                         SelectedValuePath="AccessLevelId" IsEditable="False"/>
                </DataTemplate>
              </DataGridTemplateColumn.CellEditingTemplate>
            </DataGridTemplateColumn>
          </DataGrid.Columns>
        </DataGrid>

这会引发一些错误。我究竟做错了什么?我还尝试在组合框周围放置一个网格,并将它的dataContent设置为CVS - 也没有骰子。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

<DataGridComboBoxColumn x:Name="AccessIdColumn" 
                        ItemsSource="{Binding Source={StaticResource vsAccessLevels}}" 
                        DisplayMemberPath="Description" 
                        SelectedValuePath="AccessLevelId"
                        SelectedValueBinding="{Binding Path=AccessLevelId}"/>