Click here to Skip to main content
15,943,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

In my windows form there is a datagridview and i have added checkboxes dynamically using this code
dgResult.AllowUserToAddRows = false;

                   //Below i create on check box column in the datagrid view
                   DataGridViewCheckBoxColumn colCB = new DataGridViewCheckBoxColumn();

                   //set name for the check box column
                   colCB.Name = "chkcol";
                   colCB.HeaderText = "";
                   //If you use header check box then use it
                   colCB.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;

                   //Select cell where checkbox to be display
                   Rectangle rect = this.dgResult.GetCellDisplayRectangle(0, -1, true);            //0 Column index -1(header row) is row index

                   //Mention size of the checkbox
                   chkbox.Size = new Size(18, 18);

                   //set position of header checkbox where to places
                   rect.Offset(40, 2);
                   chkbox.Location = rect.Location;

                   chkbox.CheckedChanged += chkBoxChange;

                   //Add CheckBox control to datagridView

Now i want to get the selected checkbox and get the entire row values ... Is it possible , if so can anyone help me...

Thanks in advance
praks_1 17-Jul-13 2:14am    
U can do event bubbling and get the selected row

hello friend,

Try like this...

for (int i = 0; i < GridView1.Rows.Count; i++)
               CheckBox check1=(CheckBox)GridView1.Rows[i].FindControl("Check1");

               if (check1.Checked == true)
                    String rowval1= GridView1.Rows[i].Cells[1].Text;                  
                    String rowval2 = GridView1.Rows[i].Cells[2].Text;                  
Share this answer
Thanks All For Your Answers...
I did it this way and it got me the required result
foreach (DataGridViewRow row in dgResult.Rows)
                   if (row.Cells[SelectColumnIndex].Value != null && Convert.ToBoolean(row.Cells[SelectColumnIndex].Value) == true)
                       objTempDevice.DeviceName = row.Cells["DeviceName"].Value.ToString();
                       objTempDevice.BroadworksDeviceId = row.Cells["BroadworksDeviceID"].Value.ToString();
                       objTempDevice.GroupId = row.Cells["BusinessVoIP"].Value.ToString();
                       objTempDevice.ServiceProviderId = row.Cells["ServiceProviderId"].Value.ToString();
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