数据集更新vb.net后DataGridView不刷新 [英] DataGridView does not refresh after dataset update vb.net

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

问题描述

我有一个带有 dataGridView 的 vb.net 表单

I have a vb.net form with a dataGridView

dataGridView 数据源是带有这条sql语句的dgvTableAdapter

The dataGridView data source is the dgvTableAdapter with this sql statement

SELECT membres.ID, membres.refere_par, bands.titre, 
       membres_1.prenom & ' ' & membres_1.nom  AS reference_nom
FROM ((bands INNER JOIN membres ON bands.ID = membres.[band]) 
      INNER JOIN membres membres_1 ON membres.refere_par = membres_1.ID)

我像这样从成员表中删除成员

I delete membres from the membres Table like this

' Get member id 
Dim userId As Integer 
userId = DataGridView1.Item( 0,0).Value

' Delete the member
Me.MeoshowDataSet2.membres.FindByID(userId).Delete()
Me.MembresTableAdapter.Update(Me.MeoshowDataSet2)

' Refresh datagrid
dataGridView1.Refresh() ' does nothing

我知道删除语句有效,因为我看到了数据库中的更改.如果我关闭表单并重新打开它,dataGridView 是最新的.

I know the delete statement works because I saw the changes in the database. If I close the form and reopen it, the dataGridView is up to date.

成员表是访问表

我正在 Visual 2010 调试模式下运行应用程序.

I'm running the app in visual 2010 debug mode.

推荐答案

通常的做法是重置DataGridViewDataSource.

试试这个代码(使用正确的代码从数据集中提供正确的表):

Try like this code (with correct code to provide the right table from the dataset):

dataGridView1.DataSource = typeof(List); 
dataGridView1.DataSource = dataset.Tables["your table"];

调用 .Refresh() 不起作用,因为它只会强制重新绘制,但绘制网格的代码不知道更改.

Calling .Refresh() doesn't work since it only forces a repaint, but the code that paints the grid doesn't know of the changes.

这篇关于数据集更新vb.net后DataGridView不刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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