Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello I seem to be having an issue. I have a datagridview bound to a dataset in my windows forms application. I'm hoping to find a way to refresh my datagridview after making a change to a cell. Let me go through the steps I've taken to try and accomplish this. I've added an isdirty boolean flag to the EndEdit event if the user makes any change to the datagridview. So I created a method that if the the isdirty flag is true then the changes will be written to the datasource, the program is then saved and I re-retrieve the datasource. When I try and use the refresh button the program loads for a minute and then reverts back to its original state. I can't figure out why this approach isn't working for me. I saw online something about re-binding datasources for a refresh to work, but I didn't quite understand it. If anyone has any suggestions or answers for this I would greatly appreciate any help. If this question is not clear enough please tell me how I can make it make more sense to you.


VB
'    This is how I retrieve my datasource
 Sub retrieveDGV()

   MyCommand = New OleDbDataAdapter("select * from [ExcelWorksheet$A4:I150]", MyConnection)

    DataSource = New System.Data.DataSet()
    MyCommand.Fill(DataSource)

  DGV.DataSource = DataSource.Tables(0).DefaultView



  Private Sub btnrefreshDGV_Click(sender As Object, e As EventArgs) Handles    btnrefreshDGB.Click
   refreshDGV()

   End Sub

' This is how I use the isdirty flag
  Private Sub DGV_CellEndEdit(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellEndEdit

    DGVisdirty = True
End Sub
Sub refreshDGV()
    If DGBisdirty Then
        write2DGV()
        objworkbook.Save()
        retrievedDGV()

    End If
End Sub
Posted
Updated 15-Aug-13 11:43am
v4
Comments
Richard C Bishop 15-Aug-13 17:14pm    
Are you setting the datasource again after the updating of the database?
CAS1224 15-Aug-13 17:20pm    
I'm calling my retrieve function again after the change is made. My retrieve function is pulling the data from the datasource after saving the changes.
Richard C Bishop 15-Aug-13 17:35pm    
Can you update your thread with the retrieveDGV() method code?
CAS1224 15-Aug-13 17:43pm    
Yes Let me add it

1 solution

A simple search in google brought this up: how to refresh datagridview in vb.net[^]
 
Share this answer
 
Comments
CAS1224 16-Aug-13 15:34pm    
Should I be trying to refresh the datagrid or the dataset to accomplish this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900