Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I have a project. Simply;

- There is a table in database named 'books'. Books are served on a web application. No problem till here.
- I created a desktop application which should warn the user; "a new book has been added." and then list all the books inside the desktop application. So I used datagridview and a timer. When a new book has been added into the database, gridview shows the whole records.

- Problem starts here. When the user changes the name of a book, or publishing year, this isn't being showed on the grid view till the user restart the desktop app.

C#
private void frmAnaGovde_Load(object sender, EventArgs e)
       {
           LoadBooks();
       }

       public void LoadBooks()
       {
           dataGridView1.DataSource = _books.SelectAll();
           ChangeCellContent();
       }

       public void ChangeCellContent()
       {
           dataGridView1.Columns[3].Visible = false;
           dataGridView1.Columns[4].Visible = false;
           dataGridView1.Columns[7].Visible = false;
           dataGridView1.Columns[8].Visible = false;
           dataGridView1.Columns[9].Visible = false;
           dataGridView1.Columns[11].Visible = false;
           dataGridView1.Columns[12].Visible = false;
           for (int i = 0; i < dataGridView1.Rows.Count; i++)
           {
               dataGridView1.Rows[i].Cells[0].Value = UlusoyKebapApp.n2.Sabitlerim.SIPARISDURUMU(Convert.ToInt32(dataGridView1.Rows[i].Cells[4].Value));
               dataGridView1.Rows[i].Cells[1].Value = UlusoyKebapApp.n2.Sabitlerim.ODEMESEKLI(Convert.ToInt32(dataGridView1.Rows[i].Cells[7].Value));
               dataGridView1.Rows[i].Cells[2].Value = UlusoyKebapApp.n2.Sabitlerim.PAKETSEKLI(Convert.ToInt32(dataGridView1.Rows[i].Cells[8].Value));
           }
       }

       public void InitTimer()
       {
           Zamanlayici = new Timer();
           Zamanlayici.Tick += new EventHandler(Zamanlayici_Tick);
           Zamanlayici.Interval = 2000;//
           Zamanlayici.Start();
       }
       private void Zamanlayici_Tick(object sender, EventArgs e)
       {
           LoadBooks();
       }

Do you have any solutions?
Posted
Comments
Maciej Los 29-Sep-14 12:30pm    
Why to use timer? Isn't better to update datagridview after cell edition?
DataGridView.RefreshEdit Method
Sergey Alexandrovich Kryukov 29-Sep-14 13:32pm    
It depends on the purpose, which is not clear. Such things may be needed for periodic polling of the database. Please see my answer.
—SA

P.S.: How are you Maciej? haven't here from you for a while...
Maciej Los 29-Sep-14 13:57pm    
Thank you, Sergey, i'm fine. Last week of August and first week of September i've been on holidays. I visited Austria (Vien) and Croatia (Orebic). Fantastic places! Vien is full of monuments, Orebic is a great place for windsurfing, kitesurfing and sunbath-taking. Last few weeks i had lots of business trip's, so i haven't enough time to visit this forum. I'm glad to "see you", Sergey ;) How are you?
Sergey Alexandrovich Kryukov 29-Sep-14 14:44pm    
Sounds great. Do you do windsurfing, kitesurfing? I was doing windsurfing pretty well (for a beginner) in the past, loved it.
Me? Not bad. All this time, I never left for too long, even on the trip during my vacation, which was quite good. Published a couple of articles, to reduce my debt in publications (still have a queue of some 10 articles, with source code fully complete for many of them).
—SA
Maciej Los 29-Sep-14 14:54pm    
Windsurfing, kitesurfing - no, i'll prefer to swim for long distance: 500m and more. My debt in publications is much much bigger ;) I believe i'll find a time to finish few of it to the end of this year.

1 solution

I believe the best option for you is to use SqlDependency for data change events[^].
 
Share this answer
 

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