如何刷新datagridview的在vb.net [英] How to refresh Datagridview in vb.net
问题描述
在我VB.net赢得窗体应用程序,当我点击Load按钮,我显示一个文件夹中的文件名到一个DataGridView。然后,当我点击进程按钮文件将被移动到另一个文件夹中。文件已被移动之后,网格具有被刷新。
In my VB.net win form application, when I clicked Load button I am displaying a filename from a folder onto a Datagridview. Then after I click on Process button the file will be moved to another folder. After file has been moved, Grid has to be refreshed.
下面是code我写。我能移动的文件,但没有刷新Grid.Any建议好吗?
Here is the code i have written. I can able to move the file but not refreshing the Grid.Any suggestions please?
Public Class Form1
Private Sub Load_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)Handles Load.Click
With DataGridView1
.Columns.Add("Column 0", "TaskName")
.AutoResizeColumns()
End With
Dim rowint As Integer = 0
'Dim directoryInfo As New System.IO.DirectoryInfo("C:\Users\Desktop\auto")
'Dim fileInfo = System.IO.Directory.GetFiles(directoryInfo.ToString)
'Dim name As String
DataGridView1.Rows.Add()
Dim filename As String = System.IO.Path.GetFileName("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt")
DataGridView1.Item(0, rowint).Value = filename
rowint = rowint + 1
End Sub
Private Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Process.Click
System.IO.File.Move("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt", "C:\Users\Ram\Desktop\Demo\abc.txt")
System.IO.File.Delete("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt")
DataGridView1.Refresh()
End Sub
末级
推荐答案
在刷新()
方法只能再次重新绘制现有的网格到屏幕上。您将需要通过执行点击重新加载网格的数据。这可以通过直接调用事件或通过使用 PerformClick()
方法来进行。
The Refresh()
method only redraws the existing grid to the screen again. You will need to reload the grid's data by performing a "click". This can be done by calling the event directly or by using the PerformClick()
method.
Private Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Process.Click
System.IO.File.Move("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt", "C:\Users\Ram\Desktop\Demo\abc.txt")
System.IO.File.Delete("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt")
Load_Click(Load, Nothing)
DataGridView1.Refresh()
End Sub
----或----
---- or ----
Private Sub Process_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Process.Click
System.IO.File.Move("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt", "C:\Users\Ram\Desktop\Demo\abc.txt")
System.IO.File.Delete("C:\Users\Ram\Desktop\auto\INQUEUE\123.txt")
Load.PerformClick()
DataGridView1.Refresh()
End Sub
这篇关于如何刷新datagridview的在vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!