Click here to Skip to main content
15,924,367 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have databinded a datagrid view in windows form. & also i have added a timer as well. So in the timer_tick method, i had called a method to retrieve data to the gridview from databse. But now i want to refresh the datagrid view as soon as it updates the table. I have added following code, but it doesn't work. Only it added the values from the database.

C#
private void timer1_Tick(object sender, EventArgs e)
        {
            
            this.dataGridView1.Refresh();
            this.dataGridView1.Parent.Refresh();
   

        }
Posted

See the following code, hope it helps you:

C#
protected void Timer1_Tick(object sender, EventArgs e) 
         {                  
                 FillDataGridView(); 
         } 
 
 
         protected void FillDataGridView() 
         { 
                 DataSet objDs = new DataSet(); 
                 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["Test"].ConnectionString); 
                 SqlDataAdapter myCommand; 
                 string select = "SELECT * FROM Table1"; 
                 myCommand = new SqlDataAdapter(select, myConnection); 
                 myCommand.SelectCommand.CommandType = CommandType.Text; 
                 myConnection.Open(); 
                 myCommand.Fill(objDs); 
                 GridView1.DataSource = objDs; 
                 GridView1.DataBind(); 
         }
 
Share this answer
 
v2
Comments
[no name] 20-Sep-12 4:50am    
Thank you :)
C#
this.tblCountWIPTableAdapter.Fill(this.bmaDashbordDataSet.tblCountWIP);
 
Share this answer
 
v2

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