如何向 wpfToolkit:DataGrid 添加新行(在代码中)

发布于 2024-09-25 13:16:07 字数 569 浏览 0 评论 0原文

我有 xaml:

<my:DataGrid x:Name="p_tempDataGrid"  Grid.Row="2" Grid.ColumnSpan="7" >
    <my:DataGrid.Columns>
        <my:DataGridTextColumn Header="Имя" Width="*"/>
        <my:DataGridTextColumn Header="Дата" />
        <my:DataGridTextColumn Header="Коментарии" />
        <my:DataGridTextColumn Header="Цена" />
        <my:DataGridTextColumn Header="Количество"  />
    </my:DataGrid.Columns>
</my:DataGrid>

并且我需要添加一个新行代码

tempDataGrid.Items.add(object);这个物体是什么样的?

I have xaml:

<my:DataGrid x:Name="p_tempDataGrid"  Grid.Row="2" Grid.ColumnSpan="7" >
    <my:DataGrid.Columns>
        <my:DataGridTextColumn Header="Имя" Width="*"/>
        <my:DataGridTextColumn Header="Дата" />
        <my:DataGridTextColumn Header="Коментарии" />
        <my:DataGridTextColumn Header="Цена" />
        <my:DataGridTextColumn Header="Количество"  />
    </my:DataGrid.Columns>
</my:DataGrid>

and I need to add a new row code

tempDataGrid.Items.add(object); what kind of has this object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我还没有尝试过这种方法(我建议将 DataGrid.Items 绑定到表示行的对象集合),但我想 new DataGridRow() 可以解决问题

I haven't tried this approach (I would suggest binding your DataGrid.Items to a collection of objects representing the rows), but I would imagine that new DataGridRow() would do the trick

若水微香 2024-10-02 13:16:07

我假设您已将 DataGrid.ItemsSource 属性分配给一个对象。
如果该对象是数据表,那么您向数据表添加一行,它将显示在网格上。
如果该对象实现了 ObservableCollection 接口,那么您只需将一个项目添加到该集合中,新项目就会添加到 DataGrid 中

I assume you have assigned DataGrid.ItemsSource property to an object.
If that object is a datatable then you add a row to the datatable and it would show on the grid.
If that object implemented the ObservableCollection interface then you just add an Item to that collection and the new Item gets added to the DataGrid

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文