Click here to Skip to main content
15,904,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I delete rows in datagridview using chcekbox column
I write the following code
C#
private void btndelpay_Click(object sender, EventArgs e)
{
    DialogResult dr = MessageBox.Show("delete row", "do you want to delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
    if (dr == DialogResult.Yes)
    {
        DataGridViewRow row = new DataGridViewRow();
        for (int i = 0; i < gridviewimppays.Rows.Count; i++)
        {
            row = gridviewimppays.Rows[i];
            if (Convert.ToBoolean(row.Cells[0].Value) == true)
            {
                if (ImprestsPaysMgr.DeleteImprestsPays(int.Parse(row.Cells["ID"].Value.ToString())))
                    gridviewimppays.Rows.Remove(row);
                i--;
            }
        }
    }
}

my prolblem is
how to cancel check from rows in datagridview in chechboxes column when the user select dialogResult.NO
Posted
Updated 14-Sep-14 6:01am
v2
Comments
George Jonsson 14-Sep-14 12:03pm    
Why is it so difficult to format the code properly?
The easier to read the more answers you will get.
I did it for you this time.
[no name] 14-Sep-14 12:06pm    
How would you expect the user to select Yes and No from your messagebox to begin with?
george4986 15-Sep-14 0:09am    
add an else block after
'if (dr == DialogResult.Yes) {}'
set the checkbox cells value to Falsevalue

also change the heading of the question to ur requirement
Sinisa Hajnal 15-Sep-14 3:02am    
Seconded! george, you should put this as a solution
george4986 15-Sep-14 3:29am    
what u mean by seconded? its a suggestion not a solution(his coding not checked ) also the question header is not correct

1 solution

you need to add else block for don't delete

C#
if (dr == DialogResult.No)
   {            foreach (DataRow row in ((DataTable)dataGridView1.DataSource).Rows)
            {
                if (row[0].ToString().ToLower()=="true".ToLower())
                   row[0]=false;
            }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900