wpf Datagrid :Position Listview when Datagridcell textchange
本文关键字:when Datagridcell textchange Listview Position Datagrid wpf | 更新日期: 2023-09-27 18:30:59
我想在数据网格单元格文本更改时定位列表视图。我的数据网格有一列,即产品,当用户在该列上键入某些内容时,会出现一个带有产品的小列表视图弹出窗口,因此用户可以从列表视图中选择一个产品,该产品将显示在数据网格的产品列上。我的问题是我无法将列表视图放置在我编辑的单元格附近。
我的 XAML 是:
<!--My datagrid-->
<my:DataGrid Name="dgvSales" BeginningEdit="dgvSales_BeginningEdit" VirtualizingStackPanel.IsVirtualizing="False" AutoGenerateColumns="False" Margin="13,150,9,117" KeyDown="dgvSales_KeyDown" MouseDown="dgvSales_MouseDown" PreparingCellForEdit="dgvSales_PreparingCellForEdit" >
<my:DataGrid.Columns>
<my:DataGridTextColumn x:Name="naam" Header="Code" Width="120" Binding="{Binding ProductCode}"></my:DataGridTextColumn>
<my:DataGridTextColumn Header="Product Name" Width="200" Binding="{Binding ProductName}"></my:DataGridTextColumn>
<my:DataGridComboBoxColumn Header="Unit" Width="100"></my:DataGridComboBoxColumn>
<my:DataGridTextColumn Header="Purchase Rate" Width="100" Binding="{Binding PurchaseRate}"></my:DataGridTextColumn>
<my:DataGridTextColumn Header="Qty" Width="100" Binding="{Binding Qty}"></my:DataGridTextColumn>
<my:DataGridTextColumn Header="Amount" Width="100" Binding="{Binding Amount}"></my:DataGridTextColumn>
</my:DataGrid.Columns>
</my:DataGrid>
<!--My listview-->
<ListView Height="161" ItemsSource="{Binding}" Name="lstvwProductCode" VerticalAlignment="Bottom" Width="388">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Record_Id}" Header="Record ID" Width="0" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Product_Code}" Header="Pcode" Width="110" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Product_Name}" Header="Product" Width="180" />
</GridView>
</ListView.View>
</ListView>
为什么不将列表视图放在 DataGrid 的 RowDetailsTemplate 中,并相应地设置绑定以填充列表视图。
<DataGrid.RowDetailsTemplate>
<DataTemplate>
<ListView Height="161" ItemsSource="{Binding}" Name="lstvwProductCode" VerticalAlignment="Bottom" Width="388">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=Record_Id}" Header="Record ID" Width="0" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Product_Code}" Header="Pcode" Width="110" />
<GridViewColumn DisplayMemberBinding="{Binding Path=Product_Name}" Header="Product" Width="180" />
</GridView>
</ListView.View>
</ListView>
</DataTemplate>
</DataGrid.RowDetailsTemplate>