Click here to Skip to main content
15,400,433 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a windows form application in which I have a Datagridview.

I have linked the Datagridview to a sql Server database.

I added a timer for my application to update the datagridview with new records from the database.

Now I would like to display a message (alert) to the user only when new rows are added to the datagridview and it should not stop the win form application from running.

How can I do this please please Help?

Thanks

What I have tried:

private void frmpractice1_Load(object sender, EventArgs e)
       {
           dataGridView1.DataSource = ConnectionClass.Selectcommand("Select  DISTINCT Invoice_No,Customer_Name,Time from tblAIMode  ");
           dataGridView1.RowsAdded += new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
           timer1.Interval = 5000;
           timer1.Tick += new EventHandler(UpdateDataGridView);
           timer1.Start();
       }

       private void UpdateDataGridView(object sender, EventArgs e)
       {
           dataGridView1.DataSource = ConnectionClass.Selectcommand("Select  DISTINCT Invoice_No,Customer_Name,Time from tblAIMode  ");

       }

       private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
       {
           MessageBox.Show("New Row added");
           dataGridView1.RowsAdded -= new DataGridViewRowsAddedEventHandler(dataGridView1_RowsAdded);
       }
Posted
Comments
Gerry Schmitz 23-Jun-22 19:32pm
   
Don't use a MessageBox; it's "modal". Display your message in a text field; in the same window or a different (non-modal) window. Apps often use "status bar" at the bottom of a window for "info" type messages.
Member 15627495 24-Jun-22 3:23am
   
I really agreed Gerry Smith suggestion : a messagebox will be ugly feature every five seconds.
As solution, why not making the background color of the datagrid evoluting when a new row is in... like a toggle ( seen / not seen , on a click on datagridview )
Abdul Majid 2022 8-Jul-22 15:41pm
   
Thanks But my Question is i have two forms one form for data entry and the second form is shown that data using datagridview i want to show message in the second form when first form added something in database thanks
please need help

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