GridView不会更新DataTable

时间:2013-11-25 16:13:35

标签: vb.net gridview datatable dataset devexpress

我正在为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&的参数中添加ColumnName和SourceColumn属性。更新。 Insert&的参数就属性而言,更新外观相同。

我也尝试过创建新的数据集,数据表,绑定源和tableadapter。我甚至尝试过DataAdapter,但没有区别。我现在花了两周的时间来查看属性和调试,试图找到原因。

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

1 个答案:

答案 0 :(得分:0)

问题是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.

因此,如果用户只更新了一行,那么这些更改就会无处。继续阅读代码段......

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