gpt4 book ai didi

c# - WPF 通过网格本身将行添加到 DataGrid

转载 作者:太空宇宙 更新时间:2023-11-03 10:46:52 25 4
gpt4 key购买 nike

我只是想知道是否可以通过网格本身将行添加到数据网格(因此添加到对象模型的 ObservableCollection)?

我并不是特别想使用新 View 来执行此操作(尽管如果我这样做也不会是世界末日)

谢谢

最佳答案

您可以使用 DataGrid.CanUserAddRows属性:

When this property is set to true a blank row is displayed at the bottom of the DataGrid. A user can enter a new item into the blank row. Adding a new row adds an item to the ItemsSource. You can set default values for the new item by handling the InitializingNewItem event and setting the values programmatically.

例子:

<DataGrid Name="MyDataGrid" 
CanUserAddRows="True" ... />

关于c# - WPF 通过网格本身将行添加到 DataGrid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23045736/

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