本文介绍了VB.NET:DataTable.Select()在分配BindingSource.Datasource时没有得到正确的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好..



我有一个包含3个datagridview的表单。这些网格中的每一个都有单独的bindingsource作为数据源,并且此绑定源已在Form_Load上分配为数据源作为数据源:



Hi Everyone ..

I have a form with 3 datagridview. Each of these grids has separate bindingsource as datasource and this bindingsource has been assigned datatable as datasource on Form_Load:

bsDimensions.DataSource = dtDimension
dgvDimension.DataSource = bsDimensions.DataSource

bsEntityValue.DataSource = dtEntity
dgvEntityValue.DataSource = bsEntityValue

bsCurrency.DataSource = dtCurrencies
dgvCurrency.DataSource = bsCurrency





当用户点击一行dgvDimension时,它会过滤其他2个网格的bindingSource:





When user clicks on a row of dgvDimension it filters bindingSource of other 2 grids:

bsEntityValue.Filter = "DimensionCode = '" & dgvDimension.Rows(e.RowIndex).Cells(ColDimensionCode.Index).Value & "'"
If dgvEntityValue.CurrentRow IsNot Nothing Then
    bsCurrency.Filter = "CurrencyDimensionCode = '" & dgvDimension.Rows(e.RowIndex).Cells(ColDimensionCode.Index).Value.ToString.Trim & "' And CurrencyEntityValue = '" & dgvEntityValue.CurrentRow.Cells(ColEntityValue.Index).Value.ToString.Trim & "'"
End If





请注意每个网格都有一个复选框列(RowSelected)以选择所需的行。然后,当用户单击保存按钮,然后执行以下步骤:





Please note that every grid has a checkbox column (RowSelected) to select required rows. Afterwards when user clicks Save button then following steps perform:

dgvDimension.Update()
dgvEntityValue.Update()
dgvCurrency.Update()
dgvDimension.CommitEdit(DataGridViewDataErrorContexts.Commit)
dgvEntityValue.CommitEdit(DataGridViewDataErrorContexts.Commit)
dgvCurrency.CommitEdit(DataGridViewDataErrorContexts.Commit)
dgvDimension.EndEdit()
dgvEntityValue.EndEdit()
dgvCurrency.EndEdit()
dgvDimension.Refresh()
dgvEntityValue.Refresh()
dgvCurrency.Refresh()

Dim dtEntities As Data.DataTable = bsEntityValue.DataSource
Dim dtCurrencies As Data.DataTable = bsCurrency.DataSource

Dim ResultEntities As Data.DataRow()
Dim ResultCurrency As Data.DataRow()

ResultEntities = dtEntities.Select("RowSelected=1")



现在问题是:

如果用户只点击dgvDimension中的一行并在dgvEntityValue中进行一些更改并点击保存,则此dtEntities.Select仅过滤与此特定行dgvDimension相关。同样如果用户点击让dgvDimension中的3行并进行一些更改,那么这个dtEntities.Select会过滤与这3行相关的行。



请建议可能是什么问题?为什么不过滤dtEntities中所有已检查的行。请注意,dtEntities包含所有尺寸的所有行,因此它应该选择所有被检查的行。



谢谢和问候



Zee Shan


Now here is the issue:
if user clicks just one row in "dgvDimension" and makes some changes in "dgvEntityValue" and clicks save, then this "dtEntities.Select" only filters rows which are related to this particular row of "dgvDimension". Same way if user clicks lets say 3 rows in "dgvDimension" and makes some changes, then this "dtEntities.Select" filters rows related to these 3 rows.

Please advice as what could be the issue? why isn't it filtering all checked rows in dtEntities. Please note that dtEntities contains all rows of all dimensions so it should select all rows which are checked.

Thanks and Regards

Zee Shan

推荐答案

这篇关于VB.NET:DataTable.Select()在分配BindingSource.Datasource时没有得到正确的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 11:03