从其他形式更新Xamdatagrid来源的最佳方法是什么?

发布于 2025-01-27 19:39:14 字数 634 浏览 3 评论 0原文

我的MainWindow中有一个Xamdatagrid,它具有public共享列表(Artikelstammdaten的公共共享列表)作为dataSource。打开其他表格后,我想在单击按钮时向Xamdatagrid添加更多数据。我认为最简单的方法只是更新dataSource,但我会遇到一个错误:

对未发布成员的引用需要对象参考。

这就是我尝试的:

    Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
        Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))
        dgArticleMasterData.DataSource = update
        Me.Close()
    End Sub

I have a XamDataGrid in my MainWindow which has a Public Shared List(Of Artikelstammdaten) as DataSource. After opening a few other forms I want to add more data to the XamDataGrid with a button click. I thought the easiest way would be just to update the DataSource, but I get an Error:

The reference to an unreleased member requires an object reference.

This is what I have tried:

    Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
        Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))
        dgArticleMasterData.DataSource = update
        Me.Close()
    End Sub

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

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

发布评论

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

评论(1

惟欲睡 2025-02-03 19:39:14

如果dgarticlemasterdatamainWindow类中定义,则需要获取对mainwindow实例的引用才能访问它。

您应该能够在application.current.windows集合中找到它:

Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
    Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))

    Dim window = Application.Current.Windows.OfType(Of MainWindow).FirstOrDefault()
    If window IsNot Nothing Then
        window.dgArticleMasterData.DataSource = update
    End If
    Me.Close()
End Sub

If dgArticleMasterData is defined in the MainWindow class, you need to get a reference to the MainWindow instance to be able to access it.

You should be able to find it in the Application.Current.Windows collection:

Private Sub Add_Click(sender As Object, e As RoutedEventArgs)
    Dim update = MainWindow.listArtikelstammdaten.Concat(CType(Import.ComparedAccessData, IEnumerable(Of Artikelstammdaten)))

    Dim window = Application.Current.Windows.OfType(Of MainWindow).FirstOrDefault()
    If window IsNot Nothing Then
        window.dgArticleMasterData.DataSource = update
    End If
    Me.Close()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文