如何通过使用按钮单击(网格外)获取数据网格视图中的复选框选中的行数据 [英] How to get the checkbox checked row data in datagrid view by using button click(outside of grid)

查看:91
本文介绍了如何通过使用按钮单击(网格外)获取数据网格视图中的复选框选中的行数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

colA = colB = checkbox =

================================= =============

A = B =检查CheckBox =

B = C =复选框未检查=

==============================================

--------

=提交=

--------

i想通过提交按钮从网格中获取复选框选中行值的所有单元格。

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.

推荐答案

我希望这个例子可以帮到你:



I hope this example will help you :

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
                }
            }
        }
    }
}


这篇关于如何通过使用按钮单击(网格外)获取数据网格视图中的复选框选中的行数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆