I am developing a project. In this project, the rows I selected from datagridview1 should be added to the child table and deleted from there. Later, I want to be able to add the rows that I don't want to pull from datagridview2 back to datagridview1. How do I do this?
Here is my codes:
private void button1_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM AçıkKalemler", con);
sda.Fill(dt);
dataGridView1.Rows.Clear();
foreach (DataRow item in dt.Rows)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = false; // Select butonlarının seçili olmadan gelmesini sağlar.
dataGridView1.Rows[n].Cells[1].Value = item["MÜŞTERİ"].ToString();
dataGridView1.Rows[n].Cells[2].Value = item["SIPARISNUMARASI"].ToString();
dataGridView1.Rows[n].Cells[3].Value = item["SATISNUMARASI"].ToString();
dataGridView1.Rows[n].Cells[4].Value = item["KALEMTANIMI"].ToString();
dataGridView1.Rows[n].Cells[5].Value = item["PLANLANANTESLİMTARİHİ"].ToString();
dataGridView1.Rows[n].Cells[6].Value = item["SIPARISMIKTARI"].ToString();
}
}
private void button2_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView1.Rows)
{
if ((bool)item.Cells[0].Value == true)
{
int n = dataGridView2.Rows.Add();
dataGridView2.Rows[n].Cells[0].Value = false;
dataGridView2.Rows[n].Cells[1].Value = item.Cells[1].Value.ToString();
dataGridView2.Rows[n].Cells[2].Value = item.Cells[2].Value.ToString();
dataGridView2.Rows[n].Cells[3].Value = item.Cells[3].Value.ToString();
dataGridView2.Rows[n].Cells[4].Value = item.Cells[4].Value.ToString();
dataGridView2.Rows[n].Cells[5].Value = item.Cells[5].Value.ToString();
dataGridView2.Rows[n].Cells[6].Value = item.Cells[6].Value.ToString();
}
private void dataGridView1_MouseClick(object sender, MouseEventArgs e)
{
if ((bool)dataGridView1.SelectedRows[0].Cells[0].Value == false)
{
dataGridView1.SelectedRows[0].Cells[0].Value = true;
}
else
{
dataGridView1.SelectedRows[0].Cells[0].Value = false;
}
}
private void button3_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow item in dataGridView2.Rows)
{
if ((bool)item.Cells[0].Value == true)
{
int n = dataGridView1.Rows.Add();
dataGridView1.Rows[n].Cells[0].Value = false;
dataGridView1.Rows[n].Cells[1].Value = item.Cells[1].Value.ToString();
dataGridView1.Rows[n].Cells[2].Value = item.Cells[2].Value.ToString();
dataGridView1.Rows[n].Cells[3].Value = item.Cells[3].Value.ToString();
dataGridView1.Rows[n].Cells[4].Value = item.Cells[4].Value.ToString();
dataGridView1.Rows[n].Cells[5].Value = item.Cells[5].Value.ToString();
}
}
}
private void dataGridView2_MouseClick(object sender, MouseEventArgs e)
{
if ((bool)dataGridView2.SelectedRows[0].Cells[0].Value == false)
{
dataGridView2.SelectedRows[0].Cells[0].Value = true;
}
else
{
dataGridView2.SelectedRows[0].Cells[0].Value = false;
}
}
Button3 should do this.
Please help me!!