Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
colA = colB = checkbox =
==============================================
A = B = CheckBox is Checked =
B = C = Checkbox not Checked =
==============================================
--------
=Submit=
--------
i want to get all cells of checkbox checked row value from grid by submit button.
Posted

1 solution

I hope this example will help you :

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        List<int> CheckBoxChecked = new List<int>();

        private void Form1_Load(object sender, EventArgs e)
        {
            dataGridView1.RowCount = 10;
            int i = 0;
            // Creating a test data
            foreach (DataGridViewRow Row in dataGridView1.Rows)
            {
                i++;
                Row.Cells[0].Value = i;
                Row.Cells[1].Value = i+10;

                if (i % 2 == 0) // Assigning Checked to cells whose col 1 is divisible by 2
                {
                    DataGridViewCheckBoxCell dgvcbcell = (DataGridViewCheckBoxCell) Row.Cells[2];

                    dgvcbcell.Value = true;
                }
            }

        }

        private void BtnSubmit_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow Row in dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell dgvcbcell = (DataGridViewCheckBoxCell)Row.Cells[2];

                if (true == dgvcbcell.EditedFormattedValue)
                {
                    CheckBoxChecked.Add(Row.Index+1);//Actual count is Index + 1 since index satrts from 0
                }
            }
        }
    }
}
 
Share this answer
 
v4

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