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

标签 c# wpf datagrid

我只是想知道是否可以通过网格本身将行添加到数据网格(即对象模型的 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/

相关文章:

c# - 转换为字节数组并插入到其他数组中

c# - 如何在实际迭代发生之前验证 IAsyncEnumerable 返回方法的参数?

c# - WPF 浏览器控件滚动位置

javascript - 如何在充满远程数据的 Kendo UI 网格上强制刷新?

c# - DrawImage 调整后的图像太小

c# - Azure 服务总线重试选项不起作用 (v5.2.0)

c# - 在代码隐藏 C# 中使用 DoubleAnimationUsingKeyFrames 创建 Storyboard

wpf - MVVM 窗口/区域处理

c# - WPF 工具包 DataGrid 列调整大小事件

wpf - 在 DataGridTemplateColumn 中添加图像