CheckboxCell列在Tab控件内进行检查

CheckboxCell列在Tab控件内进行检查

本文介绍了Winform:如何使DataGridView CheckboxCell列在Tab控件内进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在开发winform.我有一个Tab 控件,并且在选项卡控件中添加了一个DataGridView.正在将数据从代码绑定到DataGridView.我要在加载时检查DataGridViewCheckboxCellChecked ...这是代码

Hi All

Am working on winform. I have one Tab control and inside the tab control I added one DataGridView. Am binding the data to DataGridView from code. I want to check the DataGridViewCheckboxCell to Checked when loading... Here is the code

private void Form1_Load(object sender, EventArgs e)
{
    DataTable dt = new DataTable();
    dt.Columns.Add("name");

    DataRow dr;
    dr = dt.NewRow();
    dr["name"] = "Rajesh";

    dt.Rows.Add(dr);
    dataGridView1.DataSource = dt;


    foreach (DataGridViewRow row in dataGridView1.Rows)
    {
        ((DataGridViewCheckBoxCell)row.Cells[0]).Value = true;
    }

}


但是它不应该检查Tabcontrol内部的复选框单元格.请告诉我解决方案.


But it should not be checking the checkbox cell inside the Tabcontrol. Please tell me the solution.

推荐答案

DataTable dt = new DataTable();
dt.Columns.Add("name");

DataRow dr;
dr = dt.NewRow();
dr["name"] = "Rajesh";
dt.Rows.Add(dr);

dr = dt.NewRow();
dr["name"] = "Ratnesh";
dt.Rows.Add(dr);

DataGridViewRow dr1;
for (int i = 0; i < dt.Rows.Count; i++)
{
    dr1 = new DataGridViewRow();
    dr1.CreateCells(dataGridView1);
    dr1.Cells[0].Value = dt.Rows[i]["name"];
    dr1.Cells[1].Value = true;
    dataGridView1.Rows.Add(dr1);
}
////or u may direct add row in grid view

DataGridViewRow dr1;
dr1 = new DataGridViewRow();
dr1.CreateCells(dataGridView1);
dr1.Cells[0].Value = "Rajesh";
dr1.Cells[1].Value = true;
dataGridView1.Rows.Add(dr1);


这篇关于Winform:如何使DataGridView CheckboxCell列在Tab控件内进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:09