Twinkle Sahoo

Twinkle Sahoo

  • NA
  • 55
  • 2.9k

How to check any cells value has changed or not after checkbox select

Jun 15 2022 4:54 AM

Below code is if checkbox selection will check with count and it is more than 1 than it will call update method or else it shows message box as "Please select at least one check box".But if after selection checkbox too no values has been edited in any cells in gridview than it also gives messgae like "No records updated". I am struggling here How can I determine whether any cells value has changed or not after selecting checkbox so that base on that we can put a validation message. I am using Winform here .Please suggest.

private void btnUpdate_Click(object sender, EventArgs e)
{
    bool Msgalert = false;
    int total = dataGridView1.Rows.Cast<DataGridViewRow>().Where(p => Convert.ToBoolean(p.Cells["chkbox"].Value) == true).Count();

    DataGridViewRow row = new DataGridViewRow();
    if(total > 0 )
    {
        //if(Convert.ToString(row.Cells["polNoDataGridViewTextBoxColumn"].Value) == true||
        //    Convert.ToBoolean(row.Cells["lUBDataGridViewTextBoxColumn"].Value) == true||
        //    Convert.ToBoolean(row.Cells["EffDtDataGridViewTextBoxColumn"].Value) == true||
        //    Convert.ToBoolean(row.Cells["ExpDtDataGridViewTextBoxColumn"].Value) == true
        //    )
            Update();
    }
    else if (total == 0)
    {
        MessageBox.Instance.ShowMessageBox("Please Select at least one checkbox");
    }
}


 


Answers (6)