I have a DataGridView and Checkbox column attached to it. I would like to achieve something like this, when a few checkboxes are selected, it will compare the cells value of column named Description between those selected row. If the values are not same, a message box will be show up, else the value will be parse into a textbox.
As in example above, a messagebox should be show up when those rows are selected.
This is what i have done so far and i don't know how to continue from here.
private void datagridview1_CellClick(object sender, DataGridViewCellEventArgs e)
{
foreach (DataGridViewRow r in datagridview1.Rows)
{
bool ckboxselected = !Convert.ToBoolean(r.Cells[0].Value);
if (e.RowIndex >= 0 && e.ColumnIndex == 0)
{
if (ckboxselected)
{
//compare
}
else
{
//another action
}
}
}
}
I appreciate you help!


The CellClick event is raised when you mouse-click anywhere within the cell's bounds including the CheckBox area of the DataGridViewCheckBoxCell. Also, it's raised when you press the Space key while a content cell has focus. On the other hand, the CellContentClick event is raised when a content area (i.e. CheckBox) is hit by mouse or key and the cell's
Valueis about to change.As I understand your question, you need to implement the latter to take an action if you get different descriptions (column 2) of the checked rows. If so, a simple LINQ query will do.
If you need to skip the
nulldescriptions.Trim
.ToLower()calls for the case-sensitive comparisons.