Home > DeveloperSection > Forums > Selecting checkbox inside datagridview c#
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    March-29-2014 6:51 AM

 ASP.NET MVC ASP.NET MVC 
Ratings:


 1 Reply(s)
 1247  View(s)
Rate this:

I have a dowpdownlist, a button and a checkbox inside the datagridview.

I just only manually created a check box column on the datagridview. (here is the code)

DataGridViewCheckBoxColumn CheckboxColumn = new DataGridViewCheckBoxColumn();

            CheckBox chk = new CheckBox();

            CheckboxColumn.Width = 20;

            DataGrid1.Columns.Add(CheckboxColumn);

here is the procedure.

step 1: the user will choose item on the checkbox.

step 2: the user will choose item on the dropdown.

Step 3: the user will click on the button and it will change the itemname

on the checkbox prior to the item selected on the dropdownlist.

here is my problem after clicking on the button, nothings happen.

here is my code.

private void button1_Click(object sender, EventArgs e)

        {

    int x = 0;

                foreach (DataGridViewRow item in this.DataGrid1.SelectedRows)

                {

                    DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)item.Cells[1];

                    if (chk.Selected)

                    {

                    // codes here

                    }

                    else

                    {

                    //code here

                    }

                }

                x = x + 1;

         }



Pravesh Singh

Total Post:411

Points:2881
Posted on    March-29-2014 7:10 AM

Hi Jacob,

private void button1_Click(object sender, EventArgs e)

{

    int x = 0;

    foreach (DataGridViewRow item in this.DataGrid1.SelectedRows)

    {

        DataGridViewCheckBoxCell chk = (DataGridViewCheckBoxCell)item.Cells[1];

        if (chk.Value)

        {

              // codes here for checked condition

        }

        else

        {

              //code here  for UN-checked condition

        }

      }

     x = x + 1;

 }


Don't want to miss updates? Please click the below button!

Follow MindStick