Click here to Skip to main content
15,919,749 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I would like to throw a validation message if after selecting checkbox in gridview if there is no value edited/changed in any cells than after clicking update button it should stay on same page and throw a validation message .Please help me how can I achieve this ?

What I have tried:

if (MessageBox.Show("Would like to update then click yes!!",
                        "Input Data", MessageBoxButtons.YesNo) ==
                foreach (DataGridViewRow dgvrow in dataGridView1.SelectedRows)

                    if (Convert.ToBoolean(dgvrow.Cells["chkbox"].Selected) == true)
                        LUB = dgvrow.Cells["lUBDataGridViewTextBoxColumn"].Value.ToString();
                        POL_No = dgvrow.Cells["polNoDataGridViewTextBoxColumn"].Value.ToString();
                        POL_Effdate = Convert.ToDateTime(dgvrow.Cells["polEffDtDataGridViewTextBoxColumn"].Value);
                        POL_Expdate = Convert.ToDateTime(dgvrow.Cells["polExpDtDataGridViewTextBoxColumn"].Value);
                        tbl_pol_id = Convert.ToInt32(dgvrow.Cells["TBL_POL_ID"].Value);

                        ServClient.UpdateInputData(tbl_pol_id, LUB, POL_No, POL_Effdate, POL_Expdate);


Updated 13-Jun-22 4:42am

1 solution

It can be done like this. When reading you could store the value in both the cell.Value and cell.Tag property. When the cell.Value changes you can detect it by comparing it to the cell.Tag. Then when you successfully store the input data, you can simply update the cell.Tag with the cell.Value.

There are better ways though. You can read into DataGridView.VirtualMode Property (System.Windows.Forms) | Microsoft Docs[^]. This allows you to work with a list of objects you can use to read and write.

Also you can look into binding. This is a little harder to do (imo) [^]

HTH. Cheers
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