DataGridView:什么时候更新它的数据源??? [英] DataGridView: when does it update it's datasource???

查看:59
本文介绍了DataGridView:什么时候更新它的数据源???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,这非常令人沮丧.我根本无法理解或看到当用户将新行添加到DGV时DGV的数据源(在我的情况下为DataTable)何时更新.我已经查看了每个可能的事件在DataTable中的行计数,并且无法获取"正确的行数(我最终需要获取" DataTable的GetChanges(DataRowState.Added).


1.  DGV填充在FormLoad事件中.它包括一个ComboBoxColumn,它具有自己的数据源.一切都很好.
/>

现在,假设DGV中最初有1个单行.  DGV的底部还有一个空"行,所有单元格值都是空的. ,如果用户单击ComboBoxCol并选择一个项目,则实际上创建了一个新的friggin'行,RIGHT ??????????????? !!!!!!!!!!!! !!!!

否.不完全是.至少不是在DataTable中(DGV的数据源).

2.因此,我试图检查".查看 editingComboBox_SelectionChangeCommitted事件:

Ok, this is extremely frustrating.  I simply cannot understand or see when a DGV's DataSource (a DataTable in my case) get's updated when a new row has been added to the DGV by the user.  I have looked at row counts in the DataTable at every possible event and cannot "get" the correct number of rows (which I ultimately need to "get" the GetChanges(DataRowState.Added) of the DataTable.

So, here's what I've done.

1.  The DGV is populated on the FormLoad event.  It includes a ComboBoxColumn which has it's own datasource.  All fine.


Now, let's say initially there is 1 single row in the DGV.  There is also and "empty" row at the bottom of the DGV, all cell values are empty.  So, if the user Clicks the ComboBoxCol and chooses an item, then this actually creates a NEW friggin' row, RIGHT???????????????!!!!!!!!!!!!!!!!

No.  Not exactly.  At least NOT in the DataTable (The DGV's datasource).

2.  So, I attempted to "check".  Looked at the editingComboBox_SelectionChangeCommitted event:

Private Sub editingComboBox_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles editingComboBox.SelectionChangeCommitted

Dim rct As Integer = ImprovementsEntity.improvementTable.Rows.Count

End Sub


不. rct结果为= 1,而不是预期的2.

3.因此,我尝试检查".看了 editingComboBox_SelectedIndexChanged事件:

Private Sub editingComboBox_SelectedIndexChanged(ByVal sender As Object, _
ByVal e As System.EventArgs)

Dim rct As Integer = ImprovementsEntity.improvementTable.Rows.Count

End Sub

 不. rct结果为= 1,而不是预期的2.


4.因此,最后,我试图检查"最后一个事件.看了 DGVImprovement_UserAddedRow 事件:

 Nope.  The rct result is = 1, not 2 as expected.


4. So, finally I attempted to "check" one last event.  Looked at the DGVImprovement_UserAddedRow Event:

Private Sub DGVImprovement_UserAddedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles DGVImprovement.UserAddedRow

Dim rct As Integer = ImprovementsEntity.improvementTable.Rows.Count

End Sub


不. rct结果= 1,而不是预期的2.




我实际可以/应该在哪里或何时访问DGV的数据源以检查更改(行更新/添加) ??????????


jfc


Nope.  The rct result is = 1, not 2 as expected.



Where or WHEN can/should I actually access the DGV's DataSource to check for changes (rows update/added)??????????


jfc

推荐答案

我的朋友不强调自己. ..for 没什么...请使用Bindingsource并解决您的问题....

每次您添加新行DGV时,您都可以看到它....

Me.Bindingsource.addnew()

my friend dont stress yoourself...for  nothing...please use Bindingsource and that solve your problem....

everytime that u add a new row i DGV u will be able to see it....

Me.Bindingsource.addnew()


这篇关于DataGridView:什么时候更新它的数据源???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆