I have 2 datagridview in WinForms dgv1 dgv2 dgv1 has some columns including 1 CheckBoxColumn ,dgv2 has Some columns but no CheckBoxColumn . I want functionality which enables me , when i check CheckBoxColumn ,data of that particular Row should be selected and go into Dgv2 . this is how i put selected rows from dgv1 to dgv2 . But if i cancel check (or unckeck) ,checked checkBox in dgv1 that particular row should be deleted from dgv2 . Help me to fix this . i'll be thankful of u guys ,looking forward to this. :)
here is my code consider datagridview6= dgv1 and datagridview10 = dgv2
private void dataGridView6_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
dataGridView10.Visible = true;
if (dataGridView6.CurrentCell.ColumnIndex == 7)
{
if (dataGridView6.CurrentCell.Value != null)
{
bool checkstate = (bool)dataGridView6.CurrentCell.Value;
if (checkstate == false)
{
dataGridView6.CurrentCell.Value = true;
}
else
{//here help in logic to delete unchecked row
dataGridView6.CurrentCell.Value = false;
int j= int.Parse(dataGridView6.Rows[e.RowIndex].ToString());
dataGridView10.Rows.Remove(dataGridView10.Rows[j]);
}
}
else
{dataGridView6.CurrentCell.Value = true;
dataGridView10.Rows.Insert(i); dataGridView10.Rows[i].Cells[1].Value=dataGridView6.CurrentRow.Cells[2].Value.ToString();
dataGridView10.Rows[i].Cells[2].Value = dataGridView6.CurrentRow.Cells[3].Value.ToString();
dataGridView10.Rows[i].Cells[3].Value = dataGridView6.CurrentRow.Cells[5].Value.ToString();
}
}
/* in this logic checked row is being selected in dgv2 but on unchecking it delete is not working.
both data grid are not bound with database , m fetching value using SQlCommand class .