【问题标题】:GridView does not update DataTableGridView 不更新 DataTable
【发布时间】:2013-12-10 10:57:10
【问题描述】:

我正在为 Windows 窗体使用 DevExpress XtraGrid/View。网格的数据源是一个绑定源,它连接到一个数据集。我的问题是,这个表适配器不更新数据表。我可以毫无问题地插入新行,但无法更新。没有错误信息被抛出;当我保存更改时,行值会恢复。这发生在行中的每一列。这是我保存然后重新加载数据的代码:

            ' Class variable
            Private _invoiceDetailsAdapter As dsInvoiceDetailsTableAdapters.inv_InvoiceDetailsTableAdapter = New dsInvoiceDetailsTableAdapters.inv_InvoiceDetailsTableAdapter()

            'Save Data
            InvInvoiceLineBindingSource.EndEdit()
            _invoiceDetailsAdapter.Update(DsInvoiceDetails.inv_InvoiceDetails)

            'Load
            DsInvoiceDetails.inv_InvoiceDetails.Clear()
            If Me._invoiceId > 0 Then
                _invoiceDetailsAdapter.Fill(DsInvoiceDetails.inv_InvoiceDetails, _invoiceId)
                InvInvoiceLineBindingSource.Sort = "LineNum"
            End If

我发现它一定是数据集本身,因为我尝试将常规 DataGridView 与数据集一起使用,但无济于事。我通过向导生成了数据集,并且必须在 Insert & Update 的参数中添加 ColumnName 和 SourceColumn 属性。就属性而言,插入和更新的参数看起来相同。

我也尝试过创建新的数据集、数据表、绑定源和表适配器。我什至尝试过 DataAdapter 但没有区别。我实际上已经花了 2 周时间查看属性和调试,试图找到原因。

有人可以提供一些建议吗?

【问题讨论】:

  • 似乎只有在进行更改后移动到新行时才会更新。如果我不更改行,它不会更新,因此我可以插入。最奇怪的事情,很可能是其他地方的错误。还在寻找。如果你有什么我可以尝试的,请告诉我。

标签: vb.net gridview datatable dataset devexpress


【解决方案1】:

问题在于 DevExpress 的 XtraGrid 功能。

The XtraGrid does not immediately save an edit value to the linked dataset. The modified row is usually posted to the data object when focus is moved to another grid row. You can programmatically force the update by calling the UpdateCurrentRow method. In your case you should only call the CloseEditor and UpdateCurrentRow methods before updating the dataset via the DB adapter object.

因此,如果用户只更新一行,那么这些更改无处可去。继续阅读代码 sn-p...

http://www.devexpress.com/Support/Center/Question/Details/A327

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-02
    • 1970-01-01
    • 1970-01-01
    • 2010-10-12
    • 2018-07-15
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    相关资源
    最近更新 更多