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.
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
End Class
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 thePerformClick()method.—- or —-