当我单击“ MDM_Article_Code”行中的复选框时,我希望另一个也具有相同名称的复选框也被选中。我做到了,但是问题是当我双击它时,它坏了。
private void autoCheckWhenSameArtileCode(int rowIndex,int colIndex)
{
if (Convert.ToBoolean(dgvArticle.Rows[rowIndex].Cells[colIndex].Value))
{
string nameArticleCode = dgvArticle.Rows[rowIndex].Cells["MDM_Article_Code"].Value.ToString();
foreach (DataGridViewRow row in dgvArticle.Rows)
{
if (row.Cells["MDM_Article_Code"].Value.ToString() == nameArticleCode && row.Index != rowIndex)
{
row.Cells["colSeleted"].Value = true;
}
}
}
else
{
string nameArticleCode = dgvArticle.Rows[rowIndex].Cells["MDM_Article_Code"].Value.ToString();
foreach (DataGridViewRow row in dgvArticle.Rows)
{
if (row.Cells["MDM_Article_Code"].Value.ToString() == nameArticleCode && row.Index != rowIndex)
{
row.Cells["colSeleted"].Value = false;
}
}
}
}
private void DgvArticle_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dgvArticle.CommitEdit(DataGridViewDataErrorContexts.Commit);
}
private void DgvArticle_CellValueChanged(object sender, DataGridViewCellEventArgs e)
{
autoCheckWhenSameArtileCode(e.RowIndex,e.ColumnIndex);
}