Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi all,

I have one datagridView in my windows application in which i have inserted a checkbox column at 0 position. now i want to get the id of selected checkboxes from this grid so that at my delete button click i can raise isDelete flag for selected rows and hide them.
i am searching for the solution to get the ID but i am not getting success in that .... please help me to get the ID of selected rows.
Posted
Updated 27-Jan-12 20:59pm
v2
Comments
Sergey Alexandrovich Kryukov 28-Jan-12 2:56am    
What is ID?!
--SA

1 solution

I have found my solution. here is the code for the same

C#
private void btnDelete_Click(object sender, EventArgs e)
        {        
            foreach (DataGridViewRow Row in DataGridView1.Rows)
            {
                if (Row.Cells[0].Value != null)
                {
                    if ((bool)(Row.Cells[0].Value) == true)
                    {   
                        int tradeID = Convert.ToInt32(DataGridView1.Rows[Row.Index].Cells["ID"].Value.ToString());
// Write Update Query for the ID received here
                    }                    
                }                
            }

            loadDataGrid();
        }
 
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