2013-11-25 86 views
0

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

  ' 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与数据集试过了,没有用。我通过向导生成了数据集,并且必须在插入&更新的参数中添加ColumnName和SourceColumn属性。就属性而言,插入&更新的参数看起来完全相同。

我也试过创建新的数据集,数据表,绑定源和表适配器。我甚至尝试过DataAdapter,但没有任何区别。我现在已经花了2周时间浏览了属性和调试,试图找到一个原因。

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

+0

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

回答

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