gpt4 book ai didi

WPF 数据网格 : SelectionChanged event isn't raised when SelectionUnit ="Cell"

转载 作者:行者123 更新时间:2023-12-04 07:28:52 27 4
gpt4 key购买 nike

我正在使用 WPF 工具包数据网格。我已将其设置为 SelectionUnit="单元格" SelectionMode="扩展" .

永远不会引发 SelectionChanged 事件!

当 SelectionUnit 设置为 FullRow 时,它工作正常。

我错过了什么吗?

顺便说一句,我需要它的原因是因为我试图创建一个附加属性来帮助我将 SelectedCells 绑定(bind)到我的 ViewModel。

最佳答案

使用DataGrid.SelectedCellsChanged应该provide you用你需要的东西。

private void DG1_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
{
//Get the newly selected cells
IList<DataGridCellInfo> selectedcells = e.AddedCells;

//Get the value of each newly selected cell
foreach (DataGridCellInfo di in selectedcells)
{
//Cast the DataGridCellInfo.Item to the source object type
//In this case the ItemsSource is a DataTable and individual items are DataRows
DataRowView dvr = (DataRowView)di.Item;

//Clear values for all newly selected cells
AdventureWorksLT2008DataSet.CustomerRow cr = (AdventureWorksLT2008DataSet.CustomerRow)dvr.Row;
cr.BeginEdit();
cr.SetField(di.Column.DisplayIndex, "");
cr.EndEdit();

}
}

关于WPF 数据网格 : SelectionChanged event isn't raised when SelectionUnit ="Cell",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4714325/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com