刷新数据绑定的Datagridview [英] Refreshing databinded Datagridview

查看:56
本文介绍了刷新数据绑定的Datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题所在:

我有一个使用向导通过数据源绑定的datagridview,我使用SQL2005作为后端.
我将更改保存在数据库中,并且有一个datagridview显示所有已保存的记录,但是将更改保存在数据库中后,我的datagridview不显示立即的更改.
与Datagridview的连接是通过向导进行的,因此

Here is the problem:

I have a datagridview which is binded by datasource using wizard,I am using SQL2005 as the backend.
I am saving the changes in the database and I have a datagridview which shows all the saved records but after I save the changes in database,my datagridview does not show the immediate change.
the connection to Datagridview is via wizard so

 'TODO: This line of code loads data into the 'Equation1DataSet.TotTab' table. You can move, or remove it, as needed.
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)


在连接到数据库后,将显示上一行.

我已经尝试过


the above line appears after connection to database.

I have tried

SqlDatagridview1.Refresh()


我已经厌倦了下面的代码,使我向前走了一步,但遇到了问题.


I have tired the below code which took me 1 step ahead but with problems.

Me.TotTabTableAdapter.Dispose()
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)


上面的代码刷新了网格,但再次将所有输入项保存在网格中,我不明白为什么.

为了解决保存问题,我还尝试了EndEdit函数,该函数将指示编辑模式的结束


The above code refresh''s the grid but saves all the enteries in the grid again,I don''t understand why.

To solve the saving problem,I also tried with EndEdit function which would indicate end of edit mode

Me.TotTabBindingSource.EndEdit()
Me.TotTabTableAdapter.Dispose()
Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)


但是结果还是一样.

再次保存所有小肠可能是因为该行


But still the result is same.

The Saving of all the enteries again is may be because of the line

Me.TotTabTableAdapter.Fill(Me.Equation1DataSet.TotTab)


我也尝试了我朋友吉姆的答案之一,但问题仍然存在


I have also tried 1 of my friend Jim''s answer but still the problem exist

Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet


我的尝试:


My tries:

Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet.TotTab


Datagridview1.datasource=nothing
TotTabTableAdapter.Update(Me.Equation1DataSet.TotTab)
Datagridview1.Datasource=Me.Equation1DataSet.TotTab


结果仍然是相同的.除上述技巧外,其他任何东西都请注意.
我虽然这很简单,但我猜并非如此.

请帮助.

在此先感谢您.


The result is still the same.Any thing other than the above mentioned tricks than please suggest.
I though this would be simple but I guess its not.

Please Help..

Thanks in advance.

推荐答案

您只需要将datasource设置为空,然后将其挂回即可.这将刷新datagrid 视图.
You simply need to set the datasource to nothing and then hook it back. That will refresh the datagrid view.
Datagridview1.datasource=nothing
Datagridview1.Datasource=Me.Equation1DataSet.TotTab



这将刷新datagridview.

我忘了包括表名.抱歉..应该可以



This will refresh the datagridview.

I forgot to include the table name. Sorry.. That should work


这篇关于刷新数据绑定的Datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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